InlineStyleTagHelper Class
A TagHelper that inlines CSS files into <style> elements to reduce HTTP requests.
public sealed class InlineStyleTagHelper : InlineTagHelperRemarks
This TagHelper is particularly useful for critical CSS optimization, where you want to inline above-the-fold styles to improve initial page render performance. The CSS content is cached in memory and automatically invalidated when the source file changes.
Example
<inline-style href="site.css" />
@* Rendered as <style>/* content of wwwroot/site.css */</style> *@- Inheritance
InlineTagHelperInlineStyleTagHelper
Constructors
| Name | Description |
|---|---|
| InlineStyleTagHelper(IWebHostEnvironment, IMemoryCache, ILogger<InlineStyleTagHelper>) | Initializes a new instance of the InlineStyleTagHelper class. |
InlineStyleTagHelper(IWebHostEnvironment, IMemoryCache, ILogger<InlineStyleTagHelper>)
InlineStyleTagHelper.csInitializes a new instance of the InlineStyleTagHelper class.
public InlineStyleTagHelper(IWebHostEnvironment webHostEnvironment, IMemoryCache cache, ILogger<InlineStyleTagHelper> logger)Parameters
webHostEnvironmentIWebHostEnvironment- The web host environment for accessing web root files.
cacheIMemoryCache- The memory cache for storing file contents.
loggerILogger<InlineStyleTagHelper>- The logger used to report missing files.
Properties
| Name | Description |
|---|---|
| Href | Gets or sets the path to the CSS file relative to the web root. |
Methods
| Name | Description |
|---|---|
| ProcessAsync(TagHelperContext, TagHelperOutput) | Processes the tag helper by converting the external CSS reference to an inline <style> element. |
ProcessAsync(TagHelperContext, TagHelperOutput)
InlineStyleTagHelper.csProcesses the tag helper by converting the external CSS reference to an inline <style> element.
net10.0
public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)net11.0
public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)Parameters
contextTagHelperContext- Contains information about the current tag.
outputTagHelperOutput- A stateful HTML element used to generate an HTML tag.