Serve static files with their expected hashes for cache-busting#1524
Serve static files with their expected hashes for cache-busting#1524prandla wants to merge 1 commit intocms-dev:mainfrom
Conversation
gollux
left a comment
There was a problem hiding this comment.
I like adding hashes to URLs of static files, but I wonder how much does calculation of hashes on the fly slow down the first few requests.
Wouldn't it be better to calculate hashes of all static files when the service starts?
Also, I wonder if we can safely assume that each static file can be loaded into memory. Maybe we could use file_digest() instead?
I didn't really notice it. The files aren't that big and sha256 is not that slow. I went and measured it. Before this PR, the first load took (on average) around 380ms. Now, it's around 405ms. (Subsequent loads are around 40ms in both cases). So, clearly this isn't the worst thing that happens on first load :) (i guess it's jinja compiling its templates? dunno what else it could be.)
I think that's a bit annoying to implement; importlib.resources doesn't provide a .walk function so it's annoying to get a list of all files in the static folder.
I'm pretty sure Tornado buffers the entire response anyways (otherwise we wouldn't need FileServerMiddleware), so the file already needs to fit into memory.
|
397d156 to
df254a3
Compare
This makes it unnecessary to do a hard refresh after editing static files (especially relevant for cws_utils.js or cws_style.css), as the edited files will have a different hash and thus will be cached separately.
df254a3 to
831d6f0
Compare
…ream PR cms-dev#1524) This makes it unnecessary to do a hard refresh after editing static files (especially relevant for cws_utils.js or cws_style.css), as the edited files will have a different hash and thus will be cached separately.
This makes it unnecessary to do a hard refresh after editing static files (especially relevant for cws_utils.js or cws_style.css), as the edited files will have a different hash and thus will be cached separately.
I actually would have liked to do this for RWS too, but RWS's Ranking.html is a static file, not a jinja template. I guess we'd need some different solution for it.