2021-04-08 19:38:26 +05:30
|
|
|
<div align="center">
|
2021-07-04 15:04:14 +05:30
|
|
|
<img
|
|
|
|
width="250px"
|
|
|
|
class="greetings"
|
|
|
|
src="./examples/actix-web/static/cachable/img/Spock_vulcan-salute.png"
|
|
|
|
alt="logo image"
|
|
|
|
/>
|
|
|
|
<h1>
|
|
|
|
Cache Buster
|
|
|
|
</h1>
|
|
|
|
<p>
|
2021-07-04 15:20:14 +05:30
|
|
|
<strong>May your cache live long and prosper!</strong>
|
2021-07-04 15:04:14 +05:30
|
|
|
</p>
|
2021-04-08 19:38:26 +05:30
|
|
|
|
|
|
|
[![Documentation](https://img.shields.io/badge/docs-master-blue)](https://realaravinth.github.io/cache-buster/cache_buster/index.html)
|
|
|
|
![CI (Linux)](<https://github.com/realaravinth/cache-buster/workflows/CI%20(Linux)/badge.svg>)
|
|
|
|
[![dependency status](https://deps.rs/repo/github/realaravinth/cache-buster/status.svg)](https://deps.rs/repo/github/realaravinth/cache-buster)
|
|
|
|
<br />
|
|
|
|
[![codecov](https://codecov.io/gh/realaravinth/cache-buster/branch/master/graph/badge.svg)](https://codecov.io/gh/realaravinth/cache-buster)
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2021-05-12 18:20:26 +05:30
|
|
|
## What is cache busting?
|
|
|
|
|
|
|
|
To optimise network load time, browsers cache static files. Caching
|
|
|
|
greatly improves performance but how do you inform browsers to
|
2021-07-04 15:04:14 +05:30
|
|
|
invalidate cache when your files have changed?
|
2021-05-12 18:20:26 +05:30
|
|
|
|
|
|
|
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?
|
|
|
|
|
2021-04-08 19:38:26 +05:30
|
|
|
## Features
|
|
|
|
|
|
|
|
- [x] `SHA-256` based name generation during compile-time
|
|
|
|
- [x] Processes files based on provided MIME filters
|
2021-07-07 17:59:22 +05:30
|
|
|
- [x] Exclude certain files from processing based on file extensions
|
|
|
|
and/or file paths
|
2021-04-08 22:11:26 +05:30
|
|
|
- [x] Exposes modified names to program during runtime
|
2021-04-12 18:23:56 +05:30
|
|
|
- [x] Route prefixes(optional)
|
2021-04-08 19:38:26 +05:30
|
|
|
|
|
|
|
## Usage:
|
|
|
|
|
|
|
|
Add this to your `Cargo.toml`:
|
|
|
|
|
|
|
|
```toml
|
2021-04-30 20:41:45 +05:30
|
|
|
cache-buster = { version = "0.2", git = "https://github.com/realaravinth/cache-buster" }
|
2021-04-08 19:38:26 +05:30
|
|
|
```
|
|
|
|
|
|
|
|
## Examples:
|
|
|
|
|
2021-07-04 15:04:14 +05:30
|
|
|
- See [acix-example](./examples/actix-web)
|
2021-07-17 15:57:19 +05:30
|
|
|
- See [mCaptcha/mcaptcha](https://github.com/mCaptcha/mcaptcha) for use
|
2021-04-10 18:05:31 +05:30
|
|
|
with [Sailfish](https://crates.io/crates/sailfish) template engine.
|