Skip to content

A small helper for automatically cache busting static assets in .NET

License

Notifications You must be signed in to change notification settings

simoneldevig/CacheBuster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A small helper for automatically cache busting static assets in .NET

Resources

License

Stars

Watchers

Forks

Packages

No packages published