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-Sincepull/3776/head
parent
c8580a6dc1
commit
c1c58fa7e0
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue