From 72ce4156135f2c15a73bff7f3718862be921eb6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Ferna=CC=81ndez=20Haro?= Date: Mon, 27 Apr 2020 15:03:55 +0100 Subject: [PATCH] [SDH] Cache-Control optimizations --- .../bundles_route/dynamic_asset_response.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/optimize/bundles_route/dynamic_asset_response.js b/src/optimize/bundles_route/dynamic_asset_response.js index 80c49a26270fd..8938e1df68490 100644 --- a/src/optimize/bundles_route/dynamic_asset_response.js +++ b/src/optimize/bundles_route/dynamic_asset_response.js @@ -81,13 +81,18 @@ export async function createDynamicAssetResponse(options) { const content = replacePublicPath ? replacePlaceholder(read, publicPath) : read; const etag = replacePublicPath ? `${hash}-${publicPath}` : hash; - return h - .response(content) - .takeover() - .code(200) - .etag(etag) - .header('cache-control', 'must-revalidate') - .type(request.server.mime.path(path).type); + return ( + h + .response(content) + .takeover() + .code(200) + .etag(etag) + // We want to allow the browsers to use the cached versions onload, + // but they must-revalidate and download the newer versions in the background + // (https://github.com/elastic/support-known-issues/issues/18) + .header('cache-control', 'stale-while-revalidate=86400; max-age=0; must-revalidate') + .type(request.server.mime.path(path).type) + ); } catch (error) { if (fd) { try {