InlineScriptTagHelper Class
A TagHelper that inlines JavaScript files into <script> elements to reduce HTTP requests.
public sealed class InlineScriptTagHelper : InlineTagHelperRemarks
This TagHelper is useful for embedding small, critical JavaScript files directly in HTML to eliminate additional HTTP requests and improve initial page load performance. The script content is cached in memory and automatically invalidated when the source file changes.
Example
<inline-script src="app.js" />
@* Rendered as <script>/* content of wwwroot/app.js */</script> *@- Inheritance
InlineTagHelperInlineScriptTagHelper
Constructors
| Name | Description |
|---|---|
| InlineScriptTagHelper(IWebHostEnvironment, IMemoryCache, ILogger<InlineScriptTagHelper>) | Initializes a new instance of the InlineScriptTagHelper class. |
InlineScriptTagHelper(IWebHostEnvironment, IMemoryCache, ILogger<InlineScriptTagHelper>)
InlineScriptTagHelper.csInitializes a new instance of the InlineScriptTagHelper class.
public InlineScriptTagHelper(IWebHostEnvironment webHostEnvironment, IMemoryCache cache, ILogger<InlineScriptTagHelper> logger)Parameters
webHostEnvironmentIWebHostEnvironment- The web host environment for accessing web root files.
cacheIMemoryCache- The memory cache for storing file contents.
loggerILogger<InlineScriptTagHelper>- The logger used to report missing files.
Properties
| Name | Description |
|---|---|
| Src | Gets or sets the path to the JavaScript file relative to the web root. |
Methods
| Name | Description |
|---|---|
| ProcessAsync(TagHelperContext, TagHelperOutput) | Processes the tag helper by converting the external script reference to an inline <script> element. |
ProcessAsync(TagHelperContext, TagHelperOutput)
InlineScriptTagHelper.csProcesses the tag helper by converting the external script reference to an inline <script> 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.