Service Workers - When Fetch Goes Wrong

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

Steve Griffith - Prof3ssorSt3v3

Steve Griffith - Prof3ssorSt3v3

Күн бұрын

This is the seventh video in the Understanding Service Workers course.
This video explains how you can use your Service Worker to handle an offline-first app as well has gracefully handling 404 errors. Also discussed are CORS errors with fetch calls from your Service Worker.
Code from Video: gist.github.co...
MDN Request mode reference: developer.mozi...
MDN respondWith reference: developer.mozi...
Full Service Worker video playlist: • Service Workers - Regi...

Пікірлер: 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.
@sb_raash
@sb_raash Жыл бұрын
great explanation. solved the problem thank you very much
@Colstonewall
@Colstonewall 3 жыл бұрын
Amazing series Steve!
@wallurisatya6986
@wallurisatya6986 3 жыл бұрын
Can you make a push notification video also ? Thank you.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 жыл бұрын
It's on my todo list
@leolowe22
@leolowe22 7 ай бұрын
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 7 ай бұрын
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.
@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
@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.
@sandeshnangarepatil
@sandeshnangarepatil 7 ай бұрын
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 6 ай бұрын
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.
@RadjiMubarakElMobizy
@RadjiMubarakElMobizy 2 жыл бұрын
can service workers function even when the browser is off
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 2 жыл бұрын
No.
@addie023_6
@addie023_6 3 ай бұрын
are the fonts loaded in cache supposed to be opaque?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 ай бұрын
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.
@lllllllllIIIIIIIIIIl
@lllllllllIIIIIIIIIIl Жыл бұрын
I love you!
Service Workers - Messaging between Tabs and Service Workers
23:01
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 8 М.
Service Workers - waitUntil, skipWaiting, and claim methods
18:52
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 8 М.
Creative Justice at the Checkout: Bananas and Eggs Showdown #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 29 МЛН
А я думаю что за звук такой знакомый? 😂😂😂
00:15
Денис Кукояка
Рет қаралды 5 МЛН
How Much Tape To Stop A Lamborghini?
00:15
MrBeast
Рет қаралды 249 МЛН
7 Web Features You Didn’t Know Existed
10:16
Fireship
Рет қаралды 279 М.
PWA - Offline, Online, or Unknown
20:51
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 4,2 М.
Fetch Headers and Why They Matter
15:58
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 9 М.
Using the Fetch API - Progressive Web App Training
7:55
Chrome for Developers
Рет қаралды 16 М.
Service Workers - Registration, LifeCycle, Events, and Dev Tools
24:07
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 25 М.
Vim Tips I Wish I Knew Earlier
23:00
Sebastian Daschner
Рет қаралды 79 М.
Service Workers - The Storage API
19:46
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 4,5 М.
Ten Steps to Mastering the Fetch API
2:19:52
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 49 М.
Что такое PWA. Как работают Service Workers
51:31
Владилен Минин
Рет қаралды 113 М.
Service Workers - Controlling Every Fetch Call
19:35
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 10 М.
Creative Justice at the Checkout: Bananas and Eggs Showdown #shorts
00:18
Fabiosa Best Lifehacks
Рет қаралды 29 МЛН