Skip to content

Commit

Permalink
minify: make conditional requests work. No HTTP/304 was ever generate…
Browse files Browse the repository at this point in the history
…d 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
  • Loading branch information
Chocobozzz committed Mar 23, 2020
1 parent 2bce9f5 commit 43ca44e
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/node/utils/Minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 43ca44e

Please sign in to comment.