liveBook · Manning

Cache busting

As explained in ASP.NET Core in Action, 3e

Cache busting is a technique that changes a resource's cache identity when its contents change so clients retrieve the latest version.

Cache busting changes a resource’s cache identity when its contents change. A query parameter such as ?v=1 lets browsers reuse an unchanged file; changing it to ?v=2 triggers a fresh request for the updated file. section 18.4

Manually changing version values in every image, stylesheet, or script reference is easy to miss. ASP.NET Core’s Append Version Tag Helper avoids that work by hashing the referenced file and appending the hash as a query string. section 18.4

Version a script automatically

Add the attribute to a static asset: <script src="~/js/site.js" asp-append-version="true"></script>. The rendered URL receives a content-based value, such as /js/site.js?v=EWaMeWsJBYWmL2g_KkgXZQ5nPe. The value stays stable until the file changes, allowing browser caching while ensuring updated JavaScript is requested. section 18.4

<script src="~/js/site.js" asp-append-version="true"></script>

Inspect the concise markup pattern for enabling content-based cache busting on a script. section 18.4

How ASP.NET Core in Action, 3e covers it

How deep it goes
Defines manual query strings and explains content hashing with the Append Version Tag Helper, but does not detail caching internals.
Examples
Uses a JavaScript file, manual version values, and an asp-append-version-generated URL as concrete examples.
What it assumes
Assumes awareness of browser caching and asset URLs while explaining the query-string mechanism from its purpose.
What you can do after
Apply it via the Append Version Tag Helper to version linked, scripted, and image assets automatically.
How it connects
Connects browser caching, static assets, query parameters, and ASP.NET Core Tag Helpers.

Also explained in

Compare how 2 books explain cache busting →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.