AkurAI Build
Menu

Public repository / master

AkurAI-Framework / crates/assets/src/lib.rs

Latest change 9df51040bf1687e4dc8a91557f02df52e8d5cf3a - feat(assets): content-hash fingerprinting + conservative minifiers by Ólafur Búi Ólafsson

//! AkurAI-Framework static-asset pipeline — pure `std`, zero dependencies.
//!
//! Two correctness-first jobs for shipping static assets:
//!
//! - **Fingerprinting** ([`fingerprint`], [`hashed_name`]): derive a short,
//!   stable content hash from an asset's bytes and fold it into the filename
//!   (`app.css` ⇒ `app.<hash>.css`). The hash changes iff the bytes change, so
//!   a fingerprinted file can be served with an immutable, far-future
//!   `Cache-Control` — the URL itself is the cache key.
//! - **Minification** ([`minify_css`], [`minify_js`]): conservative,
//!   semantics-preserving size trimming. These never attempt risky
//!   transformations; correctness beats ratio (see each function's docs for the
//!   exact limits).
//!
//! ```
//! use akurai_assets::{fingerprint, hashed_name, minify_css, minify_js};
//!
//! // Same bytes → same hash; one byte differs → different hash.
//! assert_eq!(fingerprint(b"abc"), fingerprint(b"abc"));
//! assert_ne!(fingerprint(b"abc"), fingerprint(b"abd"));
//!
//! // Hash is inserted before the extension.
//! let name = hashed_name("app.css", b"body{color:red}");
//! assert!(name.starts_with("app.") && name.ends_with(".css"));
//!
//! assert_eq!(minify_css("a {\n  color: red;\n}"), "a{color:red}");
//! assert_eq!(minify_js("let x = 1; // note"), "let x = 1;");
//! ```

#![forbid(unsafe_code)]

mod fingerprint;
mod minify;

pub use fingerprint::{fingerprint, hashed_name};
pub use minify::{minify_css, minify_js};