A library that aids in static asset cache busting with SHA-256 hashes
Find a file
2021-08-30 18:17:25 +05:30
.github/workflows hash and copy 2021-04-08 19:38:26 +05:30
dist no_hash copies files 2021-07-05 15:24:56 +05:30
examples/actix-web force rerun if source changes & address clippy warnings 2021-07-11 21:48:30 +05:30
src force rerun if source changes & address clippy warnings 2021-07-11 21:48:30 +05:30
.gitignore documentation 2021-05-12 18:20:26 +05:30
Cargo.lock update deps 2021-08-30 18:17:25 +05:30
Cargo.toml steps describing actix web example 2021-07-04 15:20:14 +05:30
CHANGELOG.md update changelog 2021-07-14 21:41:46 +05:30
LICENSE-APACHE hash and copy 2021-04-08 19:38:26 +05:30
LICENSE-MIT hash and copy 2021-04-08 19:38:26 +05:30
README.md update link to mcaptcha 2021-07-17 15:57:19 +05:30

logo image

Cache Buster

May your cache live long and prosper!

Documentation CI (Linux) dependency status
codecov

What is cache busting?

To optimise network load time, browsers cache static files. Caching greatly improves performance but how do you inform browsers to invalidate cache when your files have changed?

Cache busting is a simple but effective solution for this issue. There are several ways to achieve this but the way this library does this is by changing file names to include the hash of the files' contents.

So if you have bundle.js, it will become bundle.<long-sha256-hash>.js. This lets you set a super long cache age as, because of the file names changing, the path to the filename, too, will change. So as far as the browser is concerned, you are trying to load a file that it doesn't have. Pretty neat, isn't it?

Features

  • SHA-256 based name generation during compile-time
  • Processes files based on provided MIME filters
  • Exclude certain files from processing based on file extensions and/or file paths
  • Exposes modified names to program during runtime
  • Route prefixes(optional)

Usage:

Add this to your Cargo.toml:

cache-buster = { version = "0.2", git = "https://github.com/realaravinth/cache-buster" }

Examples: