From 2288289ae93bbc674ea91dc98a594835da7b38a0 Mon Sep 17 00:00:00 2001 From: Naz Date: Wed, 5 Oct 2022 17:26:21 +0800 Subject: [PATCH] Added notes for maxAge config using express.static no issue - The milliseconds configuration here is different to "seconds" used in the max-age header value itself and other middlewares (like CORS). It's not going to be fixed upstream, so whenever this piece of code is touched again would be smart to get our own converter from seconds to milliseconds going, or some other mechanism making max-age configuration uniform across codebase --- ghost/core/core/frontend/web/middleware/static-theme.js | 2 ++ ghost/core/core/server/web/admin/app.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/ghost/core/core/frontend/web/middleware/static-theme.js b/ghost/core/core/frontend/web/middleware/static-theme.js index af07bc3e6c..4066c92a1d 100644 --- a/ghost/core/core/frontend/web/middleware/static-theme.js +++ b/ghost/core/core/frontend/web/middleware/static-theme.js @@ -32,6 +32,8 @@ function forwardToExpressStatic(req, res, next) { const configMaxAge = config.get('caching:theme:maxAge'); + // @NOTE: the maxAge config passed below are in milliseconds and the config + // is specified in seconds. See https://github.com/expressjs/serve-static/issues/150 for more context express.static(themeEngine.getActive().path, { maxAge: (configMaxAge || configMaxAge === 0) ? configMaxAge : constants.ONE_YEAR_MS } diff --git a/ghost/core/core/server/web/admin/app.js b/ghost/core/core/server/web/admin/app.js index 43fe923acc..f7cb88766b 100644 --- a/ghost/core/core/server/web/admin/app.js +++ b/ghost/core/core/server/web/admin/app.js @@ -20,6 +20,8 @@ module.exports = function setupAdminApp() { // @NOTE: when we start working on HTTP/3 optimizations the immutable headers // produced below should be split into separate 'Cache-Control' entry. // For reference see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching#validation_2 + // @NOTE: the maxAge config passed below are in milliseconds and the config + // is specified in seconds. See https://github.com/expressjs/serve-static/issues/150 for more context adminApp.use('/assets', serveStatic( path.join(config.get('paths').adminAssets, 'assets'), { maxAge: (configMaxAge || configMaxAge === 0) ? configMaxAge : constants.ONE_YEAR_MS,