-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deploy: Update js and css with hashes in filenames #240
Conversation
firebase-deployment for f53b5e3 |
Update js and css with hashes in filenames on deployment so that we can have very long (1 year) cache expiry. If the contents of the file change so will the hashes and the hashed filenames. In order for JS files to import correct hashed JS modules, generate importmap in HTML, e.g.: <script type="importmap"> { "imports": { "./module/editor.js": "./module/editor.11738c78.js", } } </script> This import statement in index.js import Editor from "./module/editor.js" will then load the correct version of editor.js. This commit is complete with regards to creating hashed filenames, however there is still work left to do to account for relative CSS and JS file references in HTML files, such as "../../css/index.css". Finally, pull it all together by marking file paths matching "**/*.*.@ (js|css)", i.e. JS and CSS filenames with a hash in their path as maximum cacheable with a 1 year expiry in firebase.json. Cache-control: max-age=31536000 headers can be observed on (preview) deployments. Link: https://jakearchibald.com/2016/caching-best-practices/ Link: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap Issue: evylang/todo#45
.github/workflows/cicd.yaml
Outdated
runs-on: ubuntu-latest | ||
environment: stage | ||
steps: | ||
- uses: actions/checkout@v3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkout is up to v4 now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool. i snuck it into the last commit.
Makefile
Outdated
# BASEURL needs to be in the environment so that `e2e/playwright.config.js` | ||
# can see it when the `e2e` target is called. | ||
export BASEURL = https://evy.dev | ||
# The firebase-deploy script sets BASEURL to the deployment URL on GitHub CI. | ||
SERVEDIR_PORT ?= 8080 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs an export for servedir to see this var
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh! thanks.
Run e2e tests against preview deployment on PRs and against https://evystage.dev, then https://evy.dev on merge to master. When run on CI the firebase_deploy script sets BASEURL_PREFIX environment variables in the GITHUB_ENV environment, e.g.: BASEURL_APEX=https://evy-lang-stage--dev-mtnwzsbm.web.app BASEURL_DISCORD=https://evy-lang-stage-discord--dev-pap726z0.web.app BASEURL_DOCS=https://evy-lang-stage-docs--dev-62qb1rk7.web.app BASEURL_LEARN=https://evy-lang-stage-learn--dev-txkb2kn8.web.app BASEURL_PLAY=https://evy-lang-stage-play--dev-t9r8zjux.web.app `make e2e` then picks them up and runs the end-to-end tests against them. `make e2e` run locally will use http://localhost:8080 be default. Update `make serve` to serve on http://localhost:8080 by default. Update github workflows to run e2e tests in separate step and deploy and e2e step in separate job, in parallel to ci.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐸
Update js and css with hashes in filenames on deployment so that we can have
very long (1 year) cache expiry. If the contents of the file change so will
the hashes and the hashed filenames.
In order for JS files to import correct hashed JS modules, generate importmap
in HTML, e.g.:
This import statement in index.js
will then load the correct version of
editor.js
.This PR is complete with regards to creating hashed filenames, however
there is still work left to account for relative CSS and JS file
references in HTML files, such as
"../../css/index.css"
.Finally, pull it all together by marking file paths matching
"**/*.*.@(js|css)"
, i.e. JS and CSS filenames with a hash in theirpath as maximum cacheable with a 1 year expiry in
firebase.json
.Cache-control: max-age=31536000
headers can be observed on(preview) deployments.
Add e2e testing against last deployed URL on CI and move deployment
and e2e into separate job.
Link: https://jakearchibald.com/2016/caching-best-practices/
Link: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap
Issue: evylang/todo#45
There is a deployment on https://evystage.dev that shows the hashed filenames,
the importmap and the long expiry Cache-control header.