CacheBuster 1.1.1

dotnet add package CacheBuster --version 1.1.1
NuGet\Install-Package CacheBuster -Version 1.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CacheBuster" Version="1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CacheBuster --version 1.1.1
#r "nuget: CacheBuster, 1.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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

Nuget Build status

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

  1. Install the Nuget package
  2. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
1.1.1 688 9/9/2020
1.1.0 417 9/9/2020
1.0.0 439 9/8/2020

Handle static files that does not exist on server