diff --git a/api/package.json b/api/package.json index e000dd8bd00..1bf99f32c47 100644 --- a/api/package.json +++ b/api/package.json @@ -61,6 +61,7 @@ "express-mongo-sanitize": "^2.2.0", "express-rate-limit": "^7.4.1", "express-session": "^1.18.1", + "express-static-gzip": "^2.2.0", "file-type": "^18.7.0", "firebase": "^11.0.2", "googleapis": "^126.0.1", diff --git a/api/server/utils/staticCache.js b/api/server/utils/staticCache.js index a8001c7e0a1..23713ddf6f3 100644 --- a/api/server/utils/staticCache.js +++ b/api/server/utils/staticCache.js @@ -1,4 +1,4 @@ -const express = require('express'); +const expressStaticGzip = require('express-static-gzip'); const oneDayInSeconds = 24 * 60 * 60; @@ -6,13 +6,13 @@ const sMaxAge = process.env.STATIC_CACHE_S_MAX_AGE || oneDayInSeconds; const maxAge = process.env.STATIC_CACHE_MAX_AGE || oneDayInSeconds * 2; const staticCache = (staticPath) => - express.static(staticPath, { - setHeaders: (res) => { - if (process.env.NODE_ENV?.toLowerCase() !== 'production') { - return; + expressStaticGzip(staticPath, { + enableBrotli: false, // disable Brotli, only using gzip + orderPreference: ['gz'], + setHeaders: (res, _path) => { + if (process.env.NODE_ENV?.toLowerCase() === 'production') { + res.setHeader('Cache-Control', `public, max-age=${maxAge}, s-maxage=${sMaxAge}`); } - - res.setHeader('Cache-Control', `public, max-age=${maxAge}, s-maxage=${sMaxAge}`); }, }); diff --git a/client/index.html b/client/index.html index 9bd0363fab2..9e300e73652 100644 --- a/client/index.html +++ b/client/index.html @@ -6,6 +6,7 @@ +