From c1c58fa7e0e1efcb3e3e999bf411e9a722098483 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 23 Mar 2020 11:34:01 +0100 Subject: [PATCH] minify: make conditional requests work. No HTTP/304 was ever generated and file were reminified uselessly. By specification [0], the if-modified-since HTTP header sent by browsers does not include milliseconds. Before this patch, let's say a file was generate at time: t_real-file = 2020-03-22T02:15:53.548Z (note the fractional seconds) When issuing a conditional request, the browser would truncate the fractional part, and only request an if-modified-since with this contents: t_if-modified-since = 2020-03-22T02:15:53.000Z The minify() function would return HTTP/304 only if t_if-modified-since >= t_real-file, but this would never be true unless, by chance, a file was generated at XX.000Z. This resulted in that file being minified/compressed again and resent to the client for no reason. After this patch, the server correctly responds with HTTP/304 without doing any computation, and the browser uses the cached file. [0] https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since --- src/node/utils/Minify.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/node/utils/Minify.js b/src/node/utils/Minify.js index d70c835c6..45aecd24a 100644 --- a/src/node/utils/Minify.js +++ b/src/node/utils/Minify.js @@ -201,6 +201,7 @@ function minify(req, res) statFile(filename, function (error, date, exists) { if (date) { date = new Date(date); + date.setMilliseconds(0); res.setHeader('last-modified', date.toUTCString()); res.setHeader('date', (new Date()).toUTCString()); if (settings.maxAge !== undefined) {