Soenneker.Blazor.Utils.ResourceLoader
4.0.1723
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Blazor.Utils.ResourceLoader --version 4.0.1723
NuGet\Install-Package Soenneker.Blazor.Utils.ResourceLoader -Version 4.0.1723
<PackageReference Include="Soenneker.Blazor.Utils.ResourceLoader" Version="4.0.1723" />
<PackageVersion Include="Soenneker.Blazor.Utils.ResourceLoader" Version="4.0.1723" />
<PackageReference Include="Soenneker.Blazor.Utils.ResourceLoader" />
paket add Soenneker.Blazor.Utils.ResourceLoader --version 4.0.1723
#r "nuget: Soenneker.Blazor.Utils.ResourceLoader, 4.0.1723"
#:package Soenneker.Blazor.Utils.ResourceLoader@4.0.1723
#addin nuget:?package=Soenneker.Blazor.Utils.ResourceLoader&version=4.0.1723
#tool nuget:?package=Soenneker.Blazor.Utils.ResourceLoader&version=4.0.1723
Soenneker.Blazor.Utils.ResourceLoader
Loads scripts and styles into a Blazor application's document, waits for browser load events, and coalesces concurrent requests that use the same URL and element options.
Installation
dotnet add package Soenneker.Blazor.Utils.ResourceLoader
Register the scoped service:
using Soenneker.Blazor.Utils.ResourceLoader.Registrars;
builder.Services.AddResourceLoaderAsScoped();
Inject IResourceLoader into a component or service:
@using Soenneker.Blazor.Utils.ResourceLoader.Abstract
@inject IResourceLoader ResourceLoader
Load a script
LoadScript appends a classic <script> element and completes after the browser fires its load event:
await ResourceLoader.LoadScript("/js/widgets.js");
For a pinned third-party asset, pass its Subresource Integrity hash. The server must also permit the requested CORS mode:
await ResourceLoader.LoadScript(
"https://cdn.example.com/widgets/3.2.1/widgets.min.js",
integrity: "sha384-...",
crossOrigin: "anonymous");
crossOrigin accepts "anonymous", "use-credentials", null, or an empty string. URLs may be relative to the document or absolute, but must resolve to HTTP or HTTPS and cannot contain embedded credentials.
Use LoadModuleScript when the resource must execute as <script type="module">:
await ResourceLoader.LoadModuleScript("/js/dashboard.js");
This loads a module script tag; it does not return the module's exports. Use a module-import interop when you need an IJSObjectReference for exported functions.
Load a stylesheet
await ResourceLoader.LoadStyle("/css/widgets.css");
The same SRI and CORS options are available for styles:
await ResourceLoader.LoadStyle(
"https://cdn.example.com/widgets/3.2.1/widgets.min.css",
integrity: "sha384-...",
crossOrigin: "anonymous",
media: "screen");
Wait for a global
Some older libraries signal readiness by assigning a browser global. Load the script and wait for a dotted global path in one operation:
await ResourceLoader.LoadScriptAndWaitForVariable(
"/js/legacy-widget.js",
"LegacyWidget.ready",
timeout: 10_000,
cancellationToken: cancellationToken);
If another part of the application loads the resource, wait without injecting another element:
await ResourceLoader.WaitForVariable(
"LegacyWidget.ready",
timeout: 10_000,
cancellationToken: cancellationToken);
Prefer an ES module import over polling for a global when the library exposes module exports.
Loading and lifetime behavior
- Concurrent calls with the same URL and options share one load operation.
- Reusing a URL with different integrity, CORS, placement, script, media, or MIME options is rejected. Keep those options consistent throughout the application.
- A failed load is removed from the loader's cache and DOM, so a later call can retry.
- Cancellation stops the .NET caller from waiting; it cannot reliably stop a browser request or undo an element already appended to the document.
- Loaded
<script>and<link>elements remain in the document. Disposing the scoped service does not unload executed JavaScript or remove applied styles. - Dynamically inserted script ordering follows browser semantics. Await each call when one script depends on another, and avoid
async: truefor order-dependent classic scripts.
Security
Loading a script grants it the same page privileges as your application. Use trusted, version-pinned HTTPS URLs. For third-party assets, use the publisher's exact SRI hash with an appropriate CORS mode and enforce a restrictive Content Security Policy. Never pass user-controlled URLs to this API.
Disposal
The dependency-injection scope disposes IResourceLoader. Manually created instances should be disposed with await using or DisposeAsync().
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Soenneker.Blazor.Utils.JsVariable (>= 4.0.1364)
NuGet packages (20)
Showing the top 5 NuGet packages that depend on Soenneker.Blazor.Utils.ResourceLoader:
| Package | Downloads |
|---|---|
|
Soenneker.Blazor.TomSelect
A Blazor interop library for the select user control library, Tom Select |
|
|
Soenneker.Blazor.FilePond
A Blazor interop library for the file upload library FilePond |
|
|
Soenneker.Blazor.Masonry
A lightweight, responsive Blazor component for Masonry (the cascading grid layout library) — perfect for image grids, cards, and dynamic content. |
|
|
Soenneker.Blazor.Turnstile
Renders a Cloudflare Turnstile widget in Blazor and exposes its token and lifecycle events. |
|
|
Soenneker.Blazor.DataTables
A Blazor interop library for DataTables |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.1729 | 0 | 9/4/2026 |
| 4.0.1728 | 1,481 | 9/1/2026 |
| 4.0.1727 | 626 | 8/31/2026 |
| 4.0.1726 | 992 | 8/31/2026 |
| 4.0.1725 | 1,017 | 8/31/2026 |
| 4.0.1724 | 209 | 8/30/2026 |
| 4.0.1723 | 382 | 8/30/2026 |
| 4.0.1722 | 1,750 | 8/30/2026 |
| 4.0.1721 | 211 | 8/30/2026 |
| 4.0.1720 | 348 | 8/30/2026 |
| 4.0.1719 | 531 | 8/29/2026 |
| 4.0.1718 | 80 | 8/29/2026 |
| 4.0.1717 | 5,851 | 8/26/2026 |
| 4.0.1716 | 702 | 8/26/2026 |
| 4.0.1715 | 2,724 | 8/21/2026 |
| 4.0.1714 | 2,868 | 8/18/2026 |
| 4.0.1713 | 2,156 | 8/13/2026 |
| 4.0.1712 | 701 | 8/12/2026 |
| 4.0.1711 | 4,834 | 8/9/2026 |
| 4.0.1710 | 1,886 | 8/8/2026 |
Update dependency Soenneker.Blazor.Utils.JsVariable to 4.0.1364 (#2268)