Instantly bust your website's cache with a fresh URL, without creating any new browser history entries.
CacheBuster.js is a tiny, zero-dependency JavaScript utility that forces a fresh page load by temporarily adding a unique cache-busting query parameter to the URL.
Once the page reloads, CacheBuster.js automatically removes the parameter without causing another reload or adding anything to the browser history.
Browsers aggressively cache websites and their resources, which can cause:
- New updates to appear outdated
- Old JavaScript and CSS files to remain cached
- Users to see stale versions of your website
- Manual hard refreshes to be required
CacheBuster.js forces a fresh page load by:
- Generating a unique cache-busting value - Uses a cryptographically secure UUID
- Reloading the current page - Temporarily adds
?cachebuster=<UUID> - Leaving no history entries - Uses
location.replace()andhistory.replaceState() - Cleaning up automatically - Removes the cache-busting parameter after the reload
- Requiring zero configuration - Just include one script
- One-Line Cache Busting - Instantly force a fresh page load
- Unique Cache-Busting Values - Uses
crypto.randomUUID()for an effectively unique value - Zero History Entries - Cache-busting never pollutes the browser's Back button history
- Automatic Cleanup - Removes the temporary query parameter after reloading
- Automatic Mode - Add the
autoclearattribute to trigger automatically - Zero Dependencies - Pure vanilla JavaScript
- Tiny Footprint - Designed to be extremely lightweight
<scriptsrc="https://cdn.jsdelivr.net/gh/AetherCodez/CacheBuster.js/cachebuster.min.js"></script># Download to your project
curl -O https://raw.githubusercontent.com/AetherCodez/CacheBuster.js/main/cachebuster.min.jsAdd one line to any webpage:
<!DOCTYPE html><html><head><title>My Website</title></head><body><!-- Your existing content --><scriptsrc="cachebuster.min.js"></script></body></html>Then call:
cachebuster.clearCache();That's it! The page reloads with a unique cache-busting value and then silently cleans the URL back up.
Want CacheBuster.js to run automatically? Add the autoclear attribute to any script tag:
<scriptsrc="https://cdn.jsdelivr.net/gh/AetherCodez/CacheBuster.js/cachebuster.min.js"
autoclear></script>CacheBuster.js will automatically perform the cache-busting reload when the page loads.
CacheBuster.js uses a simple two-step process:
- Unique URL Generation - Generates a unique UUID and adds it as the
cachebusterquery parameter - History-Free Reload - Reloads the page using
location.replace() - Automatic Detection - Detects the cache-busting parameter after the reload
- URL Cleanup - Removes the parameter using
history.replaceState()without another page reload
The result?
https://example.com/
↓
https://example.com/?cachebuster=<unique-uuid>
↓ reload
https://example.com/
The browser's history remains clean throughout the entire process.
- Ensure users receive the newest version of your website
- Bust stale browser caches after deployments
- Force updated JavaScript and CSS files to load
- Development and testing workflows
- Deployment update systems
- Website administration panels
- Static website update tools
- You need to force a fresh page load
- You want to bypass stale browser caching
- You do not want to create a new browser history entry
- You want a tiny utility without a framework or backend
- Chrome 92+
- Edge 92+
- Firefox 95+
- Safari 15.4+
Requires support for crypto.randomUUID(), location.replace(), and the History API.
Forces a fresh page load using a unique cache-busting UUID.
cachebuster.clearCache();The temporary cachebuster query parameter is automatically removed after the reload.
CacheBuster.js does not collect, transmit, or store any data.
The generated UUID is only used as a temporary cache-busting value in the page URL.
Want to see how the magic works? Check out the non-minified version:
- cachebuster.js - Full source code
- cachebuster.min.js - Production-ready minified version
The source code is intentionally tiny and easy to understand.
git clone https://github.com/AetherCodez/CacheBuster.js.git
cd CacheBuster.js
# Source: cachebuster.js (readable)# Production: cachebuster.min.js (minified)- Fork the repository
- Create a feature branch (
git checkout -b feature/improvement) - Commit your improvement (
git commit -m 'Add improvement') - Push your branch (
git push origin feature/improvement) - Open a Pull Request
MIT License - see LICENSE for details.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Star this repo if it helped you!
Force a fresh page load in seconds, without leaving a trace in browser history.
