diff --git a/phono-server/src/routes/mod.rs b/phono-server/src/routes/mod.rs index 73037e6..8e860bd 100644 --- a/phono-server/src/routes/mod.rs +++ b/phono-server/src/routes/mod.rs @@ -55,16 +55,24 @@ pub(crate) fn new_router(app: App) -> Router<()> { ServiceBuilder::new() .layer(SetResponseHeaderLayer::if_not_present( CACHE_CONTROL, - // FIXME: restore production value - // HeaderValue::from_static("max-age=21600, stale-while-revalidate=86400"), - HeaderValue::from_static("no-cache"), + HeaderValue::from_static(if cfg!(debug_assertions) { + // Disable caching when developing locally. + "no-cache" + } else { + "max-age=120, stale-while-revalidate=86400" + }), )) .service( ServeDir::new("js_dist").not_found_service( ServiceBuilder::new() .layer(SetResponseHeaderLayer::if_not_present( CACHE_CONTROL, - HeaderValue::from_static("no-cache"), + HeaderValue::from_static(if cfg!(debug_assertions) { + // Disable caching when developing locally. + "no-cache" + } else { + "max-age=120, stale-while-revalidate=86400" + }), )) .service(ServeFile::new("static/_404.html")), ), @@ -75,9 +83,12 @@ pub(crate) fn new_router(app: App) -> Router<()> { ServiceBuilder::new() .layer(SetResponseHeaderLayer::if_not_present( CACHE_CONTROL, - // FIXME: restore production value - // HeaderValue::from_static("max-age=21600, stale-while-revalidate=86400"), - HeaderValue::from_static("no-cache"), + HeaderValue::from_static(if cfg!(debug_assertions) { + // Disable caching when developing locally. + "no-cache" + } else { + "max-age=120, stale-while-revalidate=86400" + }), )) .service( ServeDir::new("css_dist").not_found_service( @@ -94,13 +105,20 @@ pub(crate) fn new_router(app: App) -> Router<()> { ServiceBuilder::new() .layer(SetResponseHeaderLayer::if_not_present( CACHE_CONTROL, - HeaderValue::from_static("max-age=21600, stale-while-revalidate=86400"), + HeaderValue::from_static(if cfg!(debug_assertions) { + // Disable caching when developing locally. + "no-cache" + } else { + "max-age=120, stale-while-revalidate=86400" + }), )) .service( ServeDir::new("static").not_found_service( ServiceBuilder::new() .layer(SetResponseHeaderLayer::if_not_present( CACHE_CONTROL, + // Do not allow caching of paths if they return + // a 404 error. HeaderValue::from_static("no-cache"), )) .service(ServeFile::new("static/_404.html")), diff --git a/svelte/vite.config.ts b/svelte/vite.config.ts index e775aa3..72d7bf7 100644 --- a/svelte/vite.config.ts +++ b/svelte/vite.config.ts @@ -15,8 +15,8 @@ export default defineConfig({ output: { dir: path.fromFileUrl(new URL("../js_dist", import.meta.url)), entryFileNames: "[name].mjs", - chunkFileNames: "[name].mjs", - assetFileNames: "[name].[ext]", + chunkFileNames: "[name]-[hash].mjs", + assetFileNames: "[name]-[hash].[ext]", }, }, sourcemap: true,