-
Notifications
You must be signed in to change notification settings - Fork 69
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
Fix: cache busting service worker #383
Conversation
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.
With this PR the service worker files are revved but they still don't have the right cache-control
header. They should be under /static/scripts
to get it automatically and right now they are in the root.
@molant I think moving the service worker files to |
@qzhou1607 that's what I though initially but I remember reading somewhere that it was scoped to were the registration was happening or under. Can't seem to find the link. |
@molant I tried having Failed to register a ServiceWorker: The path of the provided scope ('/') is not under the max scope allowed ('/static/scripts/'). Adjust the scope, move the Service Worker script, or use the Service-Worker-Allowed HTTP header to allow the scope.
(anonymous) @ sw-reg-1f4be0a30f.js:1 It does seem the location of the service worker script matters. |
😫 Can you then please take a look at https://jakearchibald.com/2016/caching-best-practices/ and make sure that we are doing the recommendations for Service Workers and how to access the resources (network first for HTML, cache first for static resources, and I don't know if something else)? |
@molant I read the blog again, we are definitely doing the right thing for accessing the resources, including:
It didn't mention anything about the right thing to do about
|
I think I'd rather change the Is there a way where we can tell the SW to go to the network first for all Also, our links don't end up in |
@molant Currently the
Did you mean the links to
|
E.g.:
I'm almost sure the SW is going to intercept that request regardless of what the header says, otherwise how would offline experiences work? |
4acc893
to
fab9134
Compare
ea0e8b0
to
3a673ad
Compare
d354419
to
ed24f2d
Compare
0772f78
to
cd1add7
Compare
647506f
to
1211334
Compare
a25daec
to
b373551
Compare
f070287
to
b373551
Compare
We don't have a SW anymore, so closing this for now. |
Pull request checklist
Make sure you:
Short description of the change(s)
service worker
cachessw-reg.js
as well. Remove that from the list of files being cached.Btw,
generate service worker
has to happen afterbuild:hexo
otherwise it can't get the right list of.html
files in the service worker. And the script has to be in the root directory otherwise the scope isn't right. So instead of copying the scripts tostatic/scripts
, I write its own gulp task.I also tried moving all
rev
andrevplace
tasks afterbuild:hexo
, hoping that we don't need to have to separate tasks for rev themes, md files and service worker that way. Butsw-reg
keeps reportingredundant
service workers and I had trouble figuring out why. So I kept the task order as it was, I'm switching to the next task now but let me know if you'd like me to keep digging on this route.