Service Workers - waitUntil, skipWaiting, and claim methods

Поделиться
HTML-код
  • Опубликовано: 15 авг 2024

Комментарии • 26

  • @vidhyarevathi9281
    @vidhyarevathi9281 3 года назад +2

    Great explanation. I surfed a lot but this helped me

  • @alighadiri6123
    @alighadiri6123 2 года назад +1

    I was so confused about update lifecycle of serviceWorkers. now I know everything thanks to you. didn't find an in-depth tutorial like this.♥

  • @derkvanderveen8938
    @derkvanderveen8938 3 года назад +2

    Great, crystal clear.

  • @iwswordpress
    @iwswordpress 3 года назад +1

    Thanks for this. SW lifecycles can be quite involved. Good explanations.

    • @StijnHommes
      @StijnHommes 3 года назад

      There is only one thing that matters: their life cycle is too long. The life cycle of a service worker should be zero seconds (or less).

  • @tomekk3569
    @tomekk3569 Год назад

    Great explanation! Thank you very much. :)

  • @wallurisatya6986
    @wallurisatya6986 3 года назад

    awesome explanation. Big fan of your tutorials.

  • @tabliqatchi6696
    @tabliqatchi6696 Год назад +1

    I've got two questions:
    1 - At 10:50 you say if we've made breaking changes we must be careful about using Clients.claim. May I know like what sort of changes would be considered breaking here?
    2 - Also at 12:17, skipWaiting is still uncommented, and when you refresh, the stuff in the install event handler don't run at all, why? What skipWaiting does is skipping the waiting to activation (of a new installation), why would it cause the other code in the install handler not to run?
    Thank you this video is great ♥

  • @expukpuk
    @expukpuk 2 года назад

    Thanks Mate, nice.

  • @leolowe22
    @leolowe22 3 месяца назад

    Thanks for the video one question though, After we claimed we still did not get fetch request interception from the updated service worker after the claim message was printed.

  • @user-ti6yk5hv7q
    @user-ti6yk5hv7q 2 года назад

    Didn't regret watching this =)
    But my sw "fetch" listener did not work if I press "clean caches and hard reset" button in chrome. Nor waitUntil() nor skipWainting() nor claim() does not help with that.
    Though claim() helped if I unregister sw in dev tools and reload.

  • @KarimShaloh
    @KarimShaloh 3 года назад +1

    Link for code gist is not included

  • @kingwindie
    @kingwindie 3 года назад

    so the self.skipWaiting will not be triggered until the .then() chains are completed? Promise is kinda confusing to me

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 года назад

      Here is my playlist about Promises to help you - ruclips.net/video/SmPouEFKOBg/видео.html

    • @kingwindie
      @kingwindie 3 года назад +1

      @@SteveGriffith-Prof3ssorSt3v3 thank you so much, really helpful videos

  • @xyz-ey7ul
    @xyz-ey7ul 2 года назад

    What's the purpose of the "controllerChange" event?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 года назад +1

      Because a service worker can be controlling multiple windows/tabs and your code can force a new service worker to take over the pages, this gives us an event to listen for.

  • @omerdavid5490
    @omerdavid5490 2 года назад

    Hey! the video is awsome.
    Do you know any way to listen "fetch" and *delay* or *block* the http request of file?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 года назад

      Inside the fetch listener and its the waitUntil( ) you can do whatever you want with the request. You can return a different file, fetch a new one from a server, send an old version from the cache and then fetch a new version from the server and put that in the cache...

    • @omerdavid5490
      @omerdavid5490 2 года назад

      @@SteveGriffith-Prof3ssorSt3v3 Its ok to do it with event.respondWith and then in the callback, delay the request?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 года назад

      @@omerdavid5490 Sorry, I meant respondWith inside the fetch event handler function. You can't create a delay though because the service worker wants to stop running.

    • @omerdavid5490
      @omerdavid5490 2 года назад

      @@SteveGriffith-Prof3ssorSt3v3 what do u mean? i tried this and its looks like its work for me . can you please explain?
      event.respondWith(
      (async function () {
      await waitTimeout(10000);
      return await fetch(event.request);
      })()
      );

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 года назад

      @@omerdavid5490 there is only so long the browser will wait before canceling the request. That goes for the service worker too.

  • @mod7ex_fx
    @mod7ex_fx Год назад