resolve http caching inconsistencies

This commit is contained in:
Brent Schroeter 2025-12-11 08:59:21 +00:00
parent 1086e95036
commit 9f13218c30

View file

@ -55,24 +55,18 @@ pub(crate) fn new_router(app: App) -> Router<()> {
ServiceBuilder::new() ServiceBuilder::new()
.layer(SetResponseHeaderLayer::if_not_present( .layer(SetResponseHeaderLayer::if_not_present(
CACHE_CONTROL, CACHE_CONTROL,
HeaderValue::from_static(if cfg!(debug_assertions) { // JS entrypoints should always be served from the current
// Disable caching when developing locally. // version.
"no-cache" HeaderValue::from_static("no-cache"),
} else {
"max-age=120, stale-while-revalidate=86400"
}),
)) ))
.service( .service(
ServeDir::new("js_dist").not_found_service( ServeDir::new("js_dist").not_found_service(
ServiceBuilder::new() ServiceBuilder::new()
.layer(SetResponseHeaderLayer::if_not_present( .layer(SetResponseHeaderLayer::if_not_present(
CACHE_CONTROL, CACHE_CONTROL,
HeaderValue::from_static(if cfg!(debug_assertions) { // Do not allow caching of paths if they return
// Disable caching when developing locally. // a 404 error.
"no-cache" HeaderValue::from_static("no-cache"),
} else {
"max-age=120, stale-while-revalidate=86400"
}),
)) ))
.service(ServeFile::new("static/_404.html")), .service(ServeFile::new("static/_404.html")),
), ),
@ -95,6 +89,8 @@ pub(crate) fn new_router(app: App) -> Router<()> {
ServiceBuilder::new() ServiceBuilder::new()
.layer(SetResponseHeaderLayer::if_not_present( .layer(SetResponseHeaderLayer::if_not_present(
CACHE_CONTROL, CACHE_CONTROL,
// Do not allow caching of paths if they return
// a 404 error.
HeaderValue::from_static("no-cache"), HeaderValue::from_static("no-cache"),
)) ))
.service(ServeFile::new("static/_404.html")), .service(ServeFile::new("static/_404.html")),