RenderOnPageLoadTagHelper Class

A TagHelper that defers rendering of content until after the page has loaded, improving perceived performance.

public sealed class RenderOnPageLoadTagHelper : TagHelper

Remarks

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
TagHelper RenderOnPageLoadTagHelper

Constructors

NameDescription
RenderOnPageLoadTagHelper()

RenderOnPageLoadTagHelper()

public RenderOnPageLoadTagHelper()

No documentation is available.

Properties

NameDescription
IdGets or sets an optional identifier for the noscript element. No identifier is emitted when not specified.

Gets or sets an optional identifier for the noscript element. No identifier is emitted when not specified.

public string? Id { get; set; }

Property value

string?

Methods

NameDescription
Process(TagHelperContext, TagHelperOutput)Processes the tag helper by wrapping content in a noscript element and adding deferred rendering script.

Process(TagHelperContext, TagHelperOutput)

RenderOnPageLoadTagHelper.cs

Processes the tag helper by wrapping content in a noscript element and adding deferred rendering script.

public override void Process(TagHelperContext context, TagHelperOutput output)

Parameters

context TagHelperContext
Contains information about the current tag.
output TagHelperOutput
A stateful HTML element used to generate an HTML tag.