Versionne les URL de app.css et app.js

Un hash du contenu est ajouté en ?v= : après un déploiement, le
navigateur recharge le CSS/JS au lieu de garder l'ancien en cache
(max-age=3600).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Romulus21andClaude Opus 5.5 committed 2026-11-13 18:39:05 +01:00
1 parent b4702fdf71
commit aa4f5aeb0a
2 files changed
+19 -10

No files matched your search

+17 -8
View File
@@ -44,18 +44,27 @@ pub fn app(pool: SqlitePool) -> Router {
)
}),
)
.route(
"/static/app.js",
get(|| asset("text/javascript", include_str!("../../static/app.js"))),
)
.route(
"/static/app.css",
get(|| asset("text/css", include_str!("../../static/app.css"))),
)
.route("/static/app.js", get(|| asset("text/javascript", APP_JS)))
.route("/static/app.css", get(|| asset("text/css", APP_CSS)))
.layer(TraceLayer::new_for_http())
.with_state(pool)
}
const APP_CSS: &str = include_str!("../../static/app.css");
const APP_JS: &str = include_str!("../../static/app.js");
/// Hash of app.css + app.js, appended as `?v=` to their URLs so a deploy
/// bypasses the browser cache.
pub fn asset_version() -> &'static str {
static VERSION: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
use std::hash::{Hash, Hasher};
let mut h = std::collections::hash_map::DefaultHasher::new();
(APP_CSS, APP_JS).hash(&mut h);
format!("{:x}", h.finish())
});
&VERSION
}
// En livereload, le CSS/JS doit être relu à chaque rechargement.
const CACHE_CONTROL: &str = if cfg!(feature = "livereload") {
"no-cache"