diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2021-03-26 21:03:34 -0400 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2021-03-26 21:03:34 -0400 |
| commit | 342a31c06cfa40be5ac50ac028578f25ce7bf0fd (patch) | |
| tree | cdbcd28cb24b07879bd81a7706e2b607d2f5fe43 /process_static | |
| parent | f5f23e2a95325f9748edcc5da4a3f21c9a18af92 (diff) | |
automate CSS/JS cache busting
Diffstat (limited to 'process_static')
| -rwxr-xr-x | process_static | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/process_static b/process_static index e0b89c45..d11e030a 100755 --- a/process_static +++ b/process_static @@ -15,6 +15,18 @@ done find static_tmp -name '*.css' -exec csso {} -o {} \; find static_tmp -name '*.js' -exec terser --module -cmo {} {} \; + +replace="" +for file in static_tmp/**/*.css static_tmp/js/*.js; do + hash=$(sha256sum "$file" | head -c 8) + dest="$(dirname $file)/$hash.$(basename $file)" + mv "$file" "$dest" + replace+=";s/\\/$(basename $file)/\\/$(basename $dest)/g" +done + +cp nginx/nginx.conf nginx.conf.tmp +sed -i "$replace" static_tmp/**/*.html nginx.conf.tmp + find static_tmp -name '*.html' -exec html-minifier --collapse-whitespace \ --process-scripts "application/ld+json" --collapse-boolean-attributes \ --remove-attribute-quotes --remove-comments --remove-empty-attributes \ |
