RenderOnPageLoadTagHelper Class
A TagHelper that defers rendering of content until after the page has loaded, improving perceived performance.
public sealed class RenderOnPageLoadTagHelper : TagHelperRemarks
This TagHelper wraps content in a <noscript> element and injects JavaScript that renders the content after the page loads. This technique is particularly useful for non-critical resources like analytics scripts or supplementary stylesheets that shouldn't block initial page rendering. For more details, see https://www.meziantou.net/loading-stylesheets-asynchronously-using-a-taghelper-in-asp-net-core.htm.
Example
@* Defer loading of non-critical stylesheet *@
<render-on-page-load>
<link rel="stylesheet" href="/css/non-critical.css" />
</render-on-page-load>
@* Defer loading with custom ID *@
<render-on-page-load id="analytics-scripts">
<script src="/js/analytics.js"></script>
</render-on-page-load>- Inheritance
TagHelperRenderOnPageLoadTagHelper
Constructors
| Name | Description |
|---|---|
| RenderOnPageLoadTagHelper() |
RenderOnPageLoadTagHelper()
public RenderOnPageLoadTagHelper()No documentation is available.
Properties
| Name | Description |
|---|---|
| Id | Gets or sets an optional identifier for the noscript element. No identifier is emitted when not specified. |
Methods
| Name | Description |
|---|---|
| Process(TagHelperContext, TagHelperOutput) | Processes the tag helper by wrapping content in a noscript element and adding deferred rendering script. |
Process(TagHelperContext, TagHelperOutput)
RenderOnPageLoadTagHelper.csProcesses the tag helper by wrapping content in a noscript element and adding deferred rendering script.
public override void Process(TagHelperContext context, TagHelperOutput output)Parameters
contextTagHelperContext- Contains information about the current tag.
outputTagHelperOutput- A stateful HTML element used to generate an HTML tag.