Fix: cache busting service worker#383
Conversation
molant
left a comment
There was a problem hiding this comment.
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:1It 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 workercachessw-reg.jsas well. Remove that from the list of files being cached.Btw,
generate service workerhas to happen afterbuild:hexootherwise it can't get the right list of.htmlfiles 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
revandrevplacetasks afterbuild:hexo, hoping that we don't need to have to separate tasks for rev themes, md files and service worker that way. Butsw-regkeeps reportingredundantservice 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.