2 unstable releases

0.3.0 Oct 16, 2023
0.2.1 Oct 16, 2023

#183 in Caching

Download history 12/week @ 2023-12-14 1/week @ 2023-12-28 7/week @ 2024-01-04 1/week @ 2024-02-08 17/week @ 2024-02-15 71/week @ 2024-02-22 32/week @ 2024-02-29 26/week @ 2024-03-07 26/week @ 2024-03-14 17/week @ 2024-03-21 8/week @ 2024-03-28

78 downloads per month

MIT/Apache

49KB
495 lines

A photo of Spock showing the Vulkan greeting

libcachebust

May your cache live long and prosper!

status-badge

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:

libcachebust = 0.2

Examples:

Dependencies

~2–3MB
~62K SLoC