[Bug]: Cache-Control max-age on streamed files is in milliseconds
Where is the problem occurring?
Server
What browsers are you seeing the problem on?
Firefox
Current behavior
serveStatic in server/config/routes.js sets
'Cache-Control': `private, max-age=${sails.config.http.cache}, immutable`,sails.config.http.cache is in milliseconds (it is Sails' input to serve-static's maxAge), so browsers receive max-age=31557600000. The directive takes seconds.
Firefox parses max-age into a 32-bit unsigned integer with an overflow check (CacheControlParser::SecondsValue) and treats a larger value as invalid. It drops the directive and falls back to heuristic freshness, so project background images, avatars and favicons re-download far more often than intended and immutable has no effect. Chrome parses the value as 64-bit and is unaffected, which is probably why this has not been noticed.
Desired behavior
max-age in seconds, so every browser keeps these files for the intended year:
'Cache-Control': `private, max-age=${Math.floor(sails.config.http.cache / 1000)}, immutable`,Steps to reproduce
- Log in on Firefox and open a project with an image background.
- In the Network panel, inspect the response for
/background-images/<id>/original.<ext>. It carriescache-control: private, max-age=31557600000, immutable. - Load the board again a few minutes later. The image is fetched again rather than served from cache.
Other information
Seen on 2.1.0. The line is unchanged on master as of de4d768.
Source: plankanban/planka