From 440edf0fbdf03fa52709138d01a91845a4628925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Tata=C5=82a?= Date: Tue, 26 May 2020 11:18:08 +0200 Subject: [PATCH] Short cache TTL for JWPlayer.js --- fastboot-server/static-assets.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fastboot-server/static-assets.js b/fastboot-server/static-assets.js index 1e481e78e9f..036da23bee5 100644 --- a/fastboot-server/static-assets.js +++ b/fastboot-server/static-assets.js @@ -1,10 +1,16 @@ const express = require('express'); const config = require('../config/fastboot-server'); +const shortTTLAssets = ['webEditor/JWPlayer.js']; + +const isShortTTLAsset = path => shortTTLAssets.some(asset => path.endsWith(asset)); + module.exports = express.static(config.distPath, { - setHeaders: (res) => { - res.set('Cache-Control', `s-maxage=${config.staticAssetsTTL}`); - res.set('X-Pass-Cache-Control', `public, max-age=${config.staticAssetsTTL}`); + setHeaders: (res, path) => { + const ttl = isShortTTLAsset(path) ? 5 * 60 : config.staticAssetsTTL; + + res.set('Cache-Control', `s-maxage=${ttl}`); + res.set('X-Pass-Cache-Control', `public, max-age=${ttl}`); res.set('Vary', 'accept-encoding'); }, });