From 50cd63eef6ce9aabe3f005708652d3f212539187 Mon Sep 17 00:00:00 2001 From: Court Ewing Date: Sun, 7 Jan 2018 15:43:59 -0500 Subject: [PATCH] [optimizer] allow http caching for bundles By setting cache-control to must-revalidate, we indicate to the browser that it should send the if-none-match header with the last known etag value. If the etags match, the server responds with a 304 and no body, and if they don't the server responds with a 200 and a body along with a new etag. This ensures a cache is always invalidated when a bundle changes, like when Kibana is upgraded or a plugin is installed. We no longer send the last-modified header because we don't want the browser caching based on time. Doing so can be unpredictable since the browser may not agree with the server's definitions of DST, and the server time itself can be changed. --- src/optimize/bundles_route/dynamic_asset_response.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/optimize/bundles_route/dynamic_asset_response.js b/src/optimize/bundles_route/dynamic_asset_response.js index 53fd9a77307b69..6212f340c15c7d 100644 --- a/src/optimize/bundles_route/dynamic_asset_response.js +++ b/src/optimize/bundles_route/dynamic_asset_response.js @@ -67,7 +67,7 @@ export async function createDynamicAssetResponse(options) { const response = request.generateResponse(replacePlaceholder(read, publicPath)); response.code(200); response.etag(`${hash}-${publicPath}`); - response.header('last-modified', stat.mtime.toUTCString()); + response.header('cache-control', 'must-revalidate'); response.type(request.server.mime.path(path).type); return response;