-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #650 from bensteinberg/add-js-cachebuster
Add JS cache-buster
- Loading branch information
Showing
4 changed files
with
22 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,17 +45,29 @@ jobs: | |
LIVE_SITE: ${{ secrets.LIVE_SITE }} | ||
run: | | ||
set -x | ||
CSS_BUST=$(find build/assets/css -type f -exec bash -c 'if [[ `diff {} <(curl -s "https://$LIVE_SITE/$(echo "{}" | cut -c 7-)")` ]]; then echo "bust ({})"; fi' \;) | ||
CSS_BUST=$(find build/assets/css build/*.config.js -type f -exec bash -c 'if [[ `diff {} <(curl -s "https://$LIVE_SITE/$(echo "{}" | cut -c 7-)")` ]]; then echo "bust ({})"; fi' \;) | ||
if [[ $CSS_BUST ]] ; then | ||
COUNTER=`grep cache-buster app/_layouts/default.html | sed -r 's/.*cache-buster=([0-9]+).*/\1/'` | ||
COUNTER=`grep css-cache-buster app/_layouts/default.html | sed -r 's/.*css-cache-buster=([0-9]+).*/\1/'` | ||
let NEWCOUNTER=$COUNTER+1 | ||
perl -pi -e "s/cache-buster=$COUNTER/cache-buster=$NEWCOUNTER/" app/_layouts/default.html | ||
perl -pi -e "s/cache-buster=$COUNTER/cache-buster=$NEWCOUNTER/" app/_includes/custom-css.html | ||
perl -pi -e "s/css-cache-buster=$COUNTER/css-cache-buster=$NEWCOUNTER/" app/_layouts/default.html | ||
perl -pi -e "s/css-cache-buster=$COUNTER/css-cache-buster=$NEWCOUNTER/" app/_includes/custom-css.html | ||
git config user.email "[email protected]" | ||
git config user.name "GitHub Actions" | ||
git add app/_layouts/default.html app/_includes/custom-css.html | ||
git commit -m 'Increment CSS cache-buster [skip ci]' | ||
git push origin redesign || exit 1 | ||
git push origin develop || exit 1 | ||
fi | ||
JS_BUST=$(find build/assets/javascripts -type f -exec bash -c 'if [[ `diff {} <(curl -s "https://$LIVE_SITE/$(echo "{}" | cut -c 7-)")` ]]; then echo "bust ({})"; fi' \;) | ||
if [[ $JS_BUST ]] ; then | ||
COUNTER=`grep js-cache-buster app/_layouts/default.html | sed -r 's/.*js-cache-buster=([0-9]+).*/\1/'` | ||
let NEWCOUNTER=$COUNTER+1 | ||
perl -pi -e "s/js-cache-buster=$COUNTER/js-cache-buster=$NEWCOUNTER/" app/_layouts/default.html | ||
perl -pi -e "s/js-cache-buster=$COUNTER/js-cache-buster=$NEWCOUNTER/" app/_includes/custom_scripts.html | ||
git config user.email "[email protected]" | ||
git config user.name "GitHub Actions" | ||
git add app/_layouts/default.html app/_includes/custom-scripts.html | ||
git commit -m 'Increment JS cache-buster [skip ci]' | ||
git push origin develop || exit 1 | ||
fi | ||
export DEPLOY_CONTENT='{"GITHUB_RUN_NUMBER":"'$GITHUB_RUN_NUMBER'","GITHUB_SHA":"'$GITHUB_SHA'","GITHUB_REF":"'$GITHUB_REF'","GITHUB_REPOSITORY":"'$GITHUB_REPOSITORY'","GITHUB_ACTOR":"'$GITHUB_ACTOR'"}' ; | ||
export DEPLOY_SIG="sha1=`echo -n "$DEPLOY_CONTENT" | openssl sha1 -hmac $DEPLOY_KEY | sed 's/^.* //'`" ; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{% if layout.custom-css %} | ||
{% for file in layout.custom-css %} | ||
<link rel="stylesheet" href="{{ site.baseurl }}/assets/css/{{ file | strip }}.css?cache-buster=52"> | ||
<link rel="stylesheet" href="{{ site.baseurl }}/assets/css/{{ file | strip }}.css?css-cache-buster=52"> | ||
{% endfor %} | ||
{% endif %} | ||
{% if page.custom-css %} | ||
{% for file in page.custom-css %} | ||
<link rel="stylesheet" href="{{ site.baseurl }}/assets/css/{{ file | strip }}.css?cache-buster=52"> | ||
<link rel="stylesheet" href="{{ site.baseurl }}/assets/css/{{ file | strip }}.css?css-cache-buster=52"> | ||
{% endfor %} | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{% if page.custom-scripts %} | ||
{% for file in page.custom-scripts %} | ||
<script src="{{ site.baseurl }}/assets/javascripts/{{ file | strip }}"></script> | ||
<script src="{{ site.baseurl }}/assets/javascripts/{{ file | strip }}?js-cache-buster=1"></script> | ||
{% endfor %} | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
<link rel="icon" href="{{ site.baseurl }}/assets/images/favicon.svg" type="image/svg+xml"> | ||
<link rel="apple-touch-icon" href="{{ site.baseurl }}/assets/images/apple-touch-favicon.png"> | ||
<link rel="manifest" href="{{ site.baseurl }}/manifest.webmanifest"> | ||
<link rel="stylesheet" href="{{ site.baseurl }}/assets/css/main.css?cache-buster=52"> | ||
<link rel="stylesheet" href="{{ site.baseurl }}/assets/css/main.css?css-cache-buster=52"> | ||
<link rel="alternate" href="{{ site.baseurl }}/blog/feed/" type="application/rss+xml" title="RSS Feed"> | ||
<script src="{{ site.baseurl }}/assets/lib/[email protected]/gsap.min.js"></script> | ||
<script src="{{ site.baseurl }}/assets/lib/[email protected]/Swup.umd.js"></script> | ||
|
@@ -27,7 +27,7 @@ | |
</main> | ||
{% include footer.html %} | ||
</div> | ||
<script src="{{ site.baseurl }}/assets/javascripts/main.js"></script> | ||
<script src="{{ site.baseurl }}/assets/javascripts/main.js?js-cache-buster=1"></script> | ||
{% include custom-scripts.html %} | ||
</body> | ||
</html> |