CacheBuster 1.1.1
dotnet add package CacheBuster --version 1.1.1
NuGet\Install-Package CacheBuster -Version 1.1.1
<PackageReference Include="CacheBuster" Version="1.1.1" />
paket add CacheBuster --version 1.1.1
#r "nuget: CacheBuster, 1.1.1"
// Install CacheBuster as a Cake Addin
#addin nuget:?package=CacheBuster&version=1.1.1
// Install CacheBuster as a Cake Tool
#tool nuget:?package=CacheBuster&version=1.1.1
CacheBuster
A small helper for automatically cache busting static assets in .NET
How it works
The helper looks at the file's last modified date and sets the timestamp as a queryparamter on the path to the static file. This means that everytime you change the file, the browser cache will update as well.
It's inspired by this article from 2014
How to use
- Install the Nuget package
- Wrap your static assset paths in the CacheBuster method ➡️
Example
@using CacheBuster;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
<link href="@CacheBuster.GetFullPath("/Content/Site.css")" rel="stylesheet">
<script src="@CacheBuster.GetFullPath("/Scripts/modernizr-2.8.3.js")"></script>
</head>
<body>
</body>
</html>
Result
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home Page - My ASP.NET Application</title>
<link href="/Content/Site.css?v=637351943954662093" rel="stylesheet">
<script src="/Scripts/modernizr-2.8.3.js?v=637351943957222104"></script>
</head>
<body>
</body>
</html>
Contributing to this project
Anyone and everyone is welcome to contribute. Just create a PR with your changes and I will have a look at it.
License
Copyright © 2020 Simon Eldevig
Licensed under the MIT License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net451 is compatible. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
This package has 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.
Handle static files that does not exist on server