Use cache busting for css/js files
On app init, short hashes are generated from file checksums to use for cache busting. These hashes are added into the full file name and used to symlink to the actual file contents. These symlinks are loaded in the jinja templates for each page, and can tell the browser to load a new file if the hash changes. This is only in place for css and js files, but can be extended in the future for other file types if needed.pull/619/head
parent
c41e0fc239
commit
68fdd55482
@ -1,2 +0,0 @@
|
||||
@import "/static/css/light-theme.css" screen;
|
||||
@import "/static/css/dark-theme.css" screen and (prefers-color-scheme: dark);
|
@ -0,0 +1,10 @@
|
||||
import hashlib
|
||||
import os
|
||||
|
||||
|
||||
def gen_file_hash(path: str, static_file: str) -> str:
|
||||
file_contents = open(os.path.join(path, static_file), 'rb').read()
|
||||
file_hash = hashlib.md5(file_contents).hexdigest()[:8]
|
||||
filename_split = os.path.splitext(static_file)
|
||||
|
||||
return filename_split[0] + '.' + file_hash + filename_split[-1]
|
Loading…
Reference in New Issue