← all packages CB

CacheBuster.js

A 25-line utility for forcing a page past a stale cache. Call cachebuster.clearCache() and it appends a fresh, one-time query parameter, reloads, then quietly cleans the URL back up.

1 global: window.cachebuster no dependencies <0.3 KB min

Live demo — simulated asset cache

current cache key a53f9c1e
style.css cached · a53f9c1e
main.js cached · a53f9c1e
logo.svg cached · a53f9c1e

Console


how it works

A disposable query parameter, nothing more

No service worker, no cache-control headers to manage, no server changes. It leans entirely on the fact that a new URL is, by definition, not yet in any cache.


Usage

Include the script, then call the global whenever you need a guaranteed-fresh load — for example after deploying a fix.

<script src="https://cdn.jsdelivr.net/gh/AetherCodez/CacheBuster.js/cachebuster.min.js"></script>

<script>
  // call this whenever a hard refresh is needed
  document.querySelector("#refresh-btn").addEventListener("click", () => {
    cachebuster.clearCache();
  });
</script>

<!-- or, clear automatically on every load: -->
<script src="cachebuster.min.js" autoclear></script>
MemberDetail
window.cachebuster.clearCache()Appends a fresh random ID as ?cachebuster= and reloads via location.replace().
autoclear attributeAdd to the script tag to call clearCache() once, automatically, on first load.
URL cleanupThe param is stripped with history.replaceState immediately after the busted load completes.