From 342a31c06cfa40be5ac50ac028578f25ce7bf0fd Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Fri, 26 Mar 2021 21:03:34 -0400 Subject: [PATCH] automate CSS/JS cache busting --- .gitignore | 1 + deploy_static | 4 ++++ nginx/nginx.conf | 2 +- process_static | 12 ++++++++++++ static/404.html | 2 +- static/articles/grapheneos-servers.html | 2 +- static/articles/index.html | 2 +- static/articles/server-traffic-shaping.html | 2 +- .../sitewide-advertising-industry-opt-out.html | 2 +- static/build.html | 4 ++-- static/contact.html | 2 +- static/donate.html | 2 +- static/faq.html | 4 ++-- static/features.html | 2 +- static/history.html | 2 +- static/index.html | 4 ++-- static/install/cli.html | 4 ++-- static/install/index.html | 4 ++-- static/install/web.html | 6 +++--- static/pdfviewer-privacy-policy.html | 2 +- static/releases.html | 6 +++--- static/source.html | 2 +- static/usage.html | 4 ++-- 23 files changed, 47 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index f6f119a7..bc2b8617 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +nginx.conf.tmp node_modules static_tmp diff --git a/deploy_static b/deploy_static index 8daeb249..3de1ed42 100755 --- a/deploy_static +++ b/deploy_static @@ -25,5 +25,9 @@ ssh $remote sync -f $target ssh $remote ln -snf $target /var/www/html ssh $remote sync . +rsync -rpcv --chmod=D755,F644 --delete nginx.conf.tmp $remote:/etc/nginx/nginx.conf +ssh $remote sync -f /etc/nginx/nginx.conf +ssh $remote systemctl reload nginx + echo echo active is now $target diff --git a/nginx/nginx.conf b/nginx/nginx.conf index cae0ed50..f1ae783c 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -67,7 +67,7 @@ http { map $http_cookie $preload_resources { "~*__Host-preload=1" ""; - default "; rel=preload; as=style, ; rel=preload; as=font; crossorigin, ; rel=preload; as=font; crossorigin, ; rel=preload; as=image"; + default "; rel=preload; as=style, ; rel=preload; as=font; crossorigin, ; rel=preload; as=font; crossorigin, ; rel=preload; as=image"; } server { 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 \ diff --git a/static/404.html b/static/404.html index b755ed62..c4a4b624 100644 --- a/static/404.html +++ b/static/404.html @@ -21,7 +21,7 @@ - + diff --git a/static/articles/grapheneos-servers.html b/static/articles/grapheneos-servers.html index d8e61d9d..08556a42 100644 --- a/static/articles/grapheneos-servers.html +++ b/static/articles/grapheneos-servers.html @@ -23,7 +23,7 @@ - + diff --git a/static/articles/index.html b/static/articles/index.html index f76f377d..aae1eb80 100644 --- a/static/articles/index.html +++ b/static/articles/index.html @@ -23,7 +23,7 @@ - + diff --git a/static/articles/server-traffic-shaping.html b/static/articles/server-traffic-shaping.html index 8ff603b0..0492c807 100644 --- a/static/articles/server-traffic-shaping.html +++ b/static/articles/server-traffic-shaping.html @@ -23,7 +23,7 @@ - + diff --git a/static/articles/sitewide-advertising-industry-opt-out.html b/static/articles/sitewide-advertising-industry-opt-out.html index b8a57026..0161d518 100644 --- a/static/articles/sitewide-advertising-industry-opt-out.html +++ b/static/articles/sitewide-advertising-industry-opt-out.html @@ -23,7 +23,7 @@ - + diff --git a/static/build.html b/static/build.html index 336c8024..f4260f72 100644 --- a/static/build.html +++ b/static/build.html @@ -23,10 +23,10 @@ - + - +
diff --git a/static/contact.html b/static/contact.html index d9a0b46d..92319e51 100644 --- a/static/contact.html +++ b/static/contact.html @@ -23,7 +23,7 @@ - + diff --git a/static/donate.html b/static/donate.html index b1f5a94b..9d440860 100644 --- a/static/donate.html +++ b/static/donate.html @@ -23,7 +23,7 @@ - + diff --git a/static/faq.html b/static/faq.html index bdd21492..d8eece2a 100644 --- a/static/faq.html +++ b/static/faq.html @@ -23,10 +23,10 @@ - + - +
diff --git a/static/features.html b/static/features.html index f2a8adfc..958d6f07 100644 --- a/static/features.html +++ b/static/features.html @@ -23,7 +23,7 @@ - + diff --git a/static/history.html b/static/history.html index cd96c0c7..6658c90b 100644 --- a/static/history.html +++ b/static/history.html @@ -23,7 +23,7 @@ - + diff --git a/static/index.html b/static/index.html index 836a7b2d..2e64e086 100644 --- a/static/index.html +++ b/static/index.html @@ -23,10 +23,10 @@ - + - +
diff --git a/static/install/cli.html b/static/install/cli.html index 930f273b..193ec94b 100644 --- a/static/install/cli.html +++ b/static/install/cli.html @@ -23,10 +23,10 @@ - + - +
diff --git a/static/install/index.html b/static/install/index.html index 97d1b624..a7387bdd 100644 --- a/static/install/index.html +++ b/static/install/index.html @@ -23,10 +23,10 @@ - + - +
diff --git a/static/install/web.html b/static/install/web.html index 2128482f..aa8bcaa5 100644 --- a/static/install/web.html +++ b/static/install/web.html @@ -23,12 +23,12 @@ - + - + - +
diff --git a/static/pdfviewer-privacy-policy.html b/static/pdfviewer-privacy-policy.html index e7b574fa..c4b809d4 100644 --- a/static/pdfviewer-privacy-policy.html +++ b/static/pdfviewer-privacy-policy.html @@ -23,7 +23,7 @@ - + diff --git a/static/releases.html b/static/releases.html index aaf7b27c..195a5c9f 100644 --- a/static/releases.html +++ b/static/releases.html @@ -24,11 +24,11 @@ - + - - + +
diff --git a/static/source.html b/static/source.html index 14b612a4..0f70af59 100644 --- a/static/source.html +++ b/static/source.html @@ -23,7 +23,7 @@ - + diff --git a/static/usage.html b/static/usage.html index 8e0c5803..cc06407c 100644 --- a/static/usage.html +++ b/static/usage.html @@ -23,10 +23,10 @@ - + - +