Writing a language-agnostic Roslyn Analyzer using IOperation

In a previous blog post, I explained how to write a Roslyn Analyzer for C#. This analyzer uses the C# syntax tree and the semantic model to detect some patterns and reports warnings. Then, the code fix can replace nodes in the C# syntax tree. So, the analyzer cannot be used for VB.NET as the syntax tree is different. This means you would need to create and maintain an analyzer for C# and another one for… [read more]

Loading stylesheets asynchronously using a TagHelper in ASP.NET Core

In a previous post, I've talked about inlining a CSS file in the html page. In term of performance, this is important to inline the critical CSS. However, the rest of the styles of the page doesn't need to be downloaded immediately. For script elements, you can simply add the attribute async to instruct the browser to load the resource asynchronously. For stylesheets, there is no equivalent. You have to… [read more]

Inlining a Stylesheet, a JavaScript, or an image file using a TagHelper in ASP.NET Core

In the previous post, I've written about inlining a Stylesheet file in the page. This allow you to reduce the number of requests required to load the page, and so to reduce the loading time of the page. The TagHelper automatically replace the tag by the content of the file at runtime, so the html document stays clean in the source code. In this post, we'll create new Tag Helpers to be able to inline CSS,… [read more]

Inlining a stylesheet using a TagHelper in ASP.NET Core

When you have a very tiny stylesheet, it may be more performant to inline it directly in the page. Indeed, it will avoid one network call, and the layout may be blocked until the browser get the response of this call. If the stylesheet is very small you may not care about caching the file on the client. For instance, on this website, the main stylesheet is 2kB large, and the full page with the inlined… [read more]

Integrating Google Analytics using dependency injection in ASP.NET Core

Integrating Google Analytics in your website is not very complicated. You just need to copy the snippet in the head tag of your page. But, there are another way to integrate it. Since ASP.NET Core 2.0, you can create a Tag Helper Component. A Tag Helper Component is a Tag Helper that allows you to conditionally modify or add HTML elements from server-side code. This allows you, for instance, to add some… [read more]

Use structures to improve the readability of your code

It's very common to use basic types such as string, int, or long to represent your data. However, sometimes there is a semantic behind the type. For instance, a string can be a file path, a full name, or an id. Also, you need to compare them or pretty-print the value. For instance, the length of a file is a long, but you almost never show the raw information. Instead, you format it as MB or GB. Which one… [read more]