snipervld.Blazor.CacheBuster
1.0.0
dotnet add package snipervld.Blazor.CacheBuster --version 1.0.0
NuGet\Install-Package snipervld.Blazor.CacheBuster -Version 1.0.0
<PackageReference Include="snipervld.Blazor.CacheBuster" Version="1.0.0" />
paket add snipervld.Blazor.CacheBuster --version 1.0.0
#r "nuget: snipervld.Blazor.CacheBuster, 1.0.0"
// Install snipervld.Blazor.CacheBuster as a Cake Addin #addin nuget:?package=snipervld.Blazor.CacheBuster&version=1.0.0 // Install snipervld.Blazor.CacheBuster as a Cake Tool #tool nuget:?package=snipervld.Blazor.CacheBuster&version=1.0.0
Blazor.CacheBuster
Blazor.CacheBuster is a library, which allows to hashify script and style URLs the way asp-append-version
ASP.NET Core's tag halper works. Also, it automatically hashify URLs within local .js
and .mjs
files during publish.
Purpose
Usually, we use service workers to prevent browsers from caching static files, but there are envirnoments, e.g. Zoom Marketplace, which forbids service workers due to security reasons. That's why this library has been build - to give us an ability to easily provide the new static files to end users without cache reset.
Framework support
.NET 6, .NET 7, .NET 8 are supported.
Installation
NuGet Package Manager Console:
Install-Package snipervld.Blazor.CacheBuster
Command line:
dotnet add package snipervld.Blazor.CacheBuster
Usage
Script and Link components
Add @using global::Blazor.CacheBuster.Components
into _Imports.razor
file.
Use the Script
and Link
components in your Blazor pages (typically, App.razor
) to automatically hashify URLs:
<Link rel="stylesheet" Href="css/fonts.css" />
<Script Src="path/to/your/script.js" />
These components works the same way the regular script
and link
HTML elements work.
.js
and .mjs
This library automatically processes all scripts during the publish, and appends hashes to import
statements, if the file or script exist in publish
directory:
// Before hashifying
import { log } from '/js/logging.js';
// After hashifying
import { log } from '/js/logging.js?v=23GFD...<hash>';
Additional MSBuild properties
BlazorCacheBuster_AdditionalFilesToHash: Specify additional files (e.g., JSON) to be included in the hashing process.
<PropertyGroup> <BlazorCacheBuster_AdditionalFilesToHash>docs/info.json</BlazorCacheBuster_AdditionalFilesToHash> </PropertyGroup>
BlazorCacheBuster_IgnoreFiles: Exclude specific scripts from being processed.
<PropertyGroup> <BlazorCacheBuster_IgnoreFiles>wwwroot/js/thirdparty.js</BlazorCacheBuster_IgnoreFiles> </PropertyGroup>
Limitations
Only native ES modules are supported.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 151 | 8/26/2024 |