Hi,
Can you please provide a demo code regarding how to alter the service-worker original logic?
I managed to append code, and I can’t manage to exclude some URL paths from being cached.
I tried the following code:
self.addEventListener('fetch', function (event) {
console.log("Fetch url:", event.request.url); // tslint:disable-line
if (event.request.url.indexOf('auth') > -1) {
console.log("Returning false"); // tslint:disable-line
return false;
}
});
Logs are written, but the path is being cached anyway.
Also, if I want to replace the whole service worker CRA code, how can I predict webpack’s file names ahead? I don’t want to eject for this.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Demo Definition & Meaning - Merriam-Webster
a · an example of a product that is not yet ready to be sold ; b · a recording intended to show...
Read more >demo - Wiktionary
(informal) A demonstration or visual explanation. · (informal) A recording of a song meant to demonstrate its overall sound for the purpose of...
Read more >Demo - Wikipedia
Demo, usually short for demonstration, may refer to: Contents. 1 Music and film; 2 Computing and technology; 3 People; 4 Other uses; 5...
Read more >Demo Definition & Meaning - Dictionary.com
to try out or exhibit the use of (a product, process, or the like): You can demo the game without downloading or buying...
Read more >DEMO: HOME
Menswear has a legacy—DEMO boldly writes a new chapter inspired by its rich heritage. Classical elements are contrasted with contemporary styling to subvert ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@CodeJjang I played a little bit and this piece of code seems to do the job:
You just have to append it to original SW.
@CodeJjang Ok, I get your point now.
First thing, the purpose of this script wasn’t to amend caching strategy of CRA. Only adding some extra features on top of it. Or replacing it completely if necessary. It’s a pretty dummy thing.
If I understand correctly you want to implement your own caching strategy.
I can suggest to solutions here:
If you look into the code of Sw generated by CRA you’ll find an array called
precacheConfig
at the beginning of the file. I’d try to append a piece of code that filters out the elements that you don’t want to be cached from that list. Sounds a little bit hacky, but could possibly work if you just want to blacklist one thing.You can also completely remove SW generated by CRA and build your own one. Have a look at sw-precache. That’s what CRA is using under the hood. It supports glob pattern matching in a config file. So you don’t really have to know the actual filenames generated by CRA build script.
Does it make sense?