[optimizer] allow http caching for bundles (#15880) (#15933)

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.
This commit is contained in:
Court Ewing 2018-01-09 13:33:45 -05:00 committed by GitHub
parent f8f8141191
commit 59726c0b75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;