Service Workers - When Fetch Goes Wrong

  Рет қаралды 5,802

Steve Griffith - Prof3ssorSt3v3

Steve Griffith - Prof3ssorSt3v3

Күн бұрын

Пікірлер: 20
@mikebryan3270
@mikebryan3270 3 жыл бұрын
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.
@Colstonewall
@Colstonewall 3 жыл бұрын
Amazing series Steve!
@sandeshnangarepatil
@sandeshnangarepatil 9 ай бұрын
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-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 8 ай бұрын
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.
@leolowe22
@leolowe22 9 ай бұрын
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-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 9 ай бұрын
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
@sb_raash Жыл бұрын
great explanation. solved the problem thank you very much
@mohamedabass2736
@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
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
When you fetch the files, you clone the response and save it in the cache, overwriting the old version.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
kzbin.info/www/bejne/p2a1fYNjeKmArNU
@mohamedabass2736
@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_6
@addie023_6 5 ай бұрын
are the fonts loaded in cache supposed to be opaque?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 5 ай бұрын
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.
@RadjiMubarakElMobizy
@RadjiMubarakElMobizy 2 жыл бұрын
can service workers function even when the browser is off
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 2 жыл бұрын
No.
@wallurisatya6986
@wallurisatya6986 3 жыл бұрын
Can you make a push notification video also ? Thank you.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 жыл бұрын
It's on my todo list
@jedosho1891
@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
@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.
@lllllllllIIIIIIIIIIl
@lllllllllIIIIIIIIIIl Жыл бұрын
I love you!
Service Workers - Messaging between Tabs and Service Workers
23:01
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 8 М.
Service Workers - The Cache API
29:48
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 18 М.
КОНЦЕРТЫ:  2 сезон | 1 выпуск | Камызяки
46:36
ТНТ Смотри еще!
Рет қаралды 3,7 МЛН
Ozoda - Alamlar (Official Video 2023)
6:22
Ozoda Official
Рет қаралды 10 МЛН
Вопрос Ребром - Джиган
43:52
Gazgolder
Рет қаралды 3,8 МЛН
PWA Tutorial for Beginners #14 - Offline Mode Explained
5:31
Net Ninja
Рет қаралды 53 М.
Что такое PWA. Как работают Service Workers
51:31
Владилен Минин
Рет қаралды 114 М.
Service Workers - waitUntil, skipWaiting, and claim methods
18:52
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 8 М.
Service Workers - Controlling Every Fetch Call
19:35
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 10 М.
Coding a Web Server in 25 Lines - Computerphile
17:49
Computerphile
Рет қаралды 362 М.
Service Workers - The Storage API
19:46
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 4,7 М.
Always Check for the Hidden API when Web Scraping
11:50
John Watson Rooney
Рет қаралды 662 М.
Build an e-commerce site... with a twist - Web Dev Challenge S1E3
26:20
Learn With Jason
Рет қаралды 264 М.
КОНЦЕРТЫ:  2 сезон | 1 выпуск | Камызяки
46:36
ТНТ Смотри еще!
Рет қаралды 3,7 МЛН