documentation
This commit is contained in:
parent
874dec8180
commit
d970b7031c
4 changed files with 55 additions and 2 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -4,3 +4,5 @@ tarpaulin-report.html
|
|||
actix-example/target
|
||||
actix-example/prod
|
||||
prod56/
|
||||
src/cache_buster_data.json
|
||||
actix-example/src/cache_buster_data.json
|
||||
|
|
19
README.md
19
README.md
|
@ -1,7 +1,8 @@
|
|||
<div align="center">
|
||||
<h1>Cache Buster</h1>
|
||||
<p>
|
||||
<strong>cache-buster - A library that aids in staticfile cache busting with SHA-258 hashes</strong>
|
||||
<strong>cache-buster - A library that aids in static file cache
|
||||
busting with SHA-256 hashes</strong>
|
||||
</p>
|
||||
|
||||
[![Documentation](https://img.shields.io/badge/docs-master-blue)](https://realaravinth.github.io/cache-buster/cache_buster/index.html)
|
||||
|
@ -12,6 +13,22 @@
|
|||
|
||||
</div>
|
||||
|
||||
## 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
|
||||
|
||||
- [x] `SHA-256` based name generation during compile-time
|
||||
|
|
File diff suppressed because one or more lines are too long
35
src/lib.rs
35
src/lib.rs
|
@ -5,6 +5,25 @@
|
|||
* License.
|
||||
*/
|
||||
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
|
||||
//! # 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?
|
||||
//!
|
||||
//! ## Example:
|
||||
//!
|
||||
//! - `build.rs`
|
||||
//! ```no_run
|
||||
//! use cache_buster::BusterBuilder;
|
||||
//!
|
||||
|
@ -30,6 +49,22 @@
|
|||
//! config.process().unwrap();
|
||||
//! }
|
||||
//! ```
|
||||
//! - `main.rs`:
|
||||
//!
|
||||
//! Module describing runtime compoenet for fetching modified filenames
|
||||
//!
|
||||
//! Add the following tou your program to load the filemap during compiletime:
|
||||
//!
|
||||
//! ```no_run
|
||||
//! use cache_buster::Files;
|
||||
//! use cache_buster::CACHE_BUSTER_DATA_FILE;
|
||||
//!
|
||||
//! fn main(){
|
||||
//! let files = Files::new(CACHE_BUSTER_DATA_FILE);
|
||||
//! // the path to the file before setting up for cache busting
|
||||
//! files.get("./dist/github.svg");
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
pub mod processor;
|
||||
pub use processor::BusterBuilder;
|
||||
|
|
Loading…
Reference in a new issue