Skip to content

StaticScriptRenderer

Inherits: TagHelper HTML Target: <render-static-scripts />

StaticScriptRenderer is a tag helper that outputs all scripts that were teleported via StaticScript components using the teleport-script attribute. It acts as the collection point where deferred scripts are rendered into the page.

TechGems.StaticComponents
<render-static-scripts />

This is a self-closing tag with no end tag (void element).

Place <render-static-scripts /> in your layout, typically just before the closing </body> tag:

~/Pages/Shared/_Layout.cshtml
<html>
<head>...</head>
<body>
@RenderBody()
<render-static-scripts />
</body>
</html>

Any <script static-script teleport-script> blocks in your components will be collected during rendering and output at this location.

[HtmlAttributeNotBound]
[ViewContext]
public ViewContext? ViewContext { get; set; }

The View Context injected by ASP.NET Core at runtime. Used to access HttpContext.Items, where teleported scripts are stored. This property should not be set manually.

  1. Reads the list of teleported scripts from HttpContext.Items.
  2. If no scripts were teleported, suppresses output entirely (no HTML is rendered).
  3. If scripts exist, renders them wrapped in HTML comments for easy identification:
<!-- Static Scripts -->
<script>console.log("teleported script 1");</script>
<script>console.log("teleported script 2");</script>
<!-- Static Scripts End -->