A super introduction to service worker. I have coded a few PWA's and always had issues with how to implement a 404 page. Thanks for providing a clear solution to a complex problem.
@Colstonewall3 жыл бұрын
Amazing series Steve!
@sandeshnangarepatil9 ай бұрын
Hi Steve, I’m currently calling an API every 5 minutes from my service worker and storing the data in IndexedDB. I’d like to continue this process even when I close my browser window, similar to how background sync works. How can I achieve this?
@SteveGriffith-Prof3ssorSt3v38 ай бұрын
Service Workers get shut down by the browser. They are only given a few seconds to run. You can't keep them running. Even if you use ev.waitUntil(), there is a limit to how long it will wait. You need an event trigger to wake the service worker up. If the webpage makes a fetch call, that will trigger the fetch listener in the worker and wake up the script. Same thing with the browser window. When it closes, all its scripts stop running. When a page is moved into the background and no longer active the browser wants to stop the scripts as soon as possible.
@leolowe229 ай бұрын
Hi Route related stuff is generally handled by frameworks when online, 404 pages are available for non existen routes so in the online cases do we still need to handle that in service workers?
@SteveGriffith-Prof3ssorSt3v39 ай бұрын
Absolutely. A service worker is like a proxy server between the website and the server. It makes decisions about what is working and what is not. It might have access to pages in the cache or it might not. If the browser is offline then the service worker is making all these decisions because the server that does the routing is completely out of reach.
@sb_raash Жыл бұрын
great explanation. solved the problem thank you very much
@mohamedabass2736 Жыл бұрын
how can i update any of the files that the service worker gets from the cache? whenever i put some content (lets say in an html file) that content never shows up in the page because the worker handling the fetch requests always gets the older file? i even tried to rename the file but it always matches the older one
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
When you fetch the files, you clone the response and save it in the cache, overwriting the old version.
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
kzbin.info/www/bejne/p2a1fYNjeKmArNU
@mohamedabass2736 Жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 thanks for the reply. i did clone the response and saved it in the cache... after that the service worker will match the request(url of the file) but in my case it gets the older version of the response(the one that i just saved) not the new one with the new content
@addie023_65 ай бұрын
are the fonts loaded in cache supposed to be opaque?
@SteveGriffith-Prof3ssorSt3v35 ай бұрын
If things like fonts and images are fetched from external domains and don't meet the CORS rules then they will be opaque. Which means that the browser is allowed to load them by you can't load them via JS.
@RadjiMubarakElMobizy2 жыл бұрын
can service workers function even when the browser is off
@SteveGriffith-Prof3ssorSt3v32 жыл бұрын
No.
@wallurisatya69863 жыл бұрын
Can you make a push notification video also ? Thank you.
@SteveGriffith-Prof3ssorSt3v33 жыл бұрын
It's on my todo list
@jedosho1891 Жыл бұрын
Hi Steve. I have a problem. when I set "opts" as a parameter in fetch event (Line 90), the function of going to "nowhere.html" stops working, and when I delete that parameter it works again. I do not know why that happens. :(
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
the "navigate" value for the mode option is no allowed to be set in script. Only the browser can set that one. So, if the value is "navigate" then leave it out of your options.