Unchanged service worker is re-installing and re-caching

后端 未结 2 1012
醉梦人生
醉梦人生 2021-01-03 15:13

I\'m registering my service worker, and in the registered callback, loading some cached files

if (\'serviceWorker\' in navigator) {
    navigator.serviceWork         


        
相关标签:
2条回答
  • 2021-01-03 15:39

    It should not be there because the install event is called only once.I think the issue is in your chrome browser force update service worker is checked.Open developer console on chrome -> go to application tab -> service worker and uncheck update on reload.

    0 讨论(0)
  • 2021-01-03 15:56

    So the very first time the service worker is installed, I see 3 cache hits, for the 3 files I'm loading. If I close and re-open, I get 6, then 9, etc. In any case, simply refreshing the page shows the original 3 cache hits as expected.

    Most probably is that you are seeing previous logs. To verify, you can show the timeline of every log.

    1. Go to dev tools settings F1 inside console or click on the icon (img1)
    2. Check the option Show timestamps (img2).
    3. Or simple add a console.log(new Date()); inside your fetch event handler.

    Img1


    Img2



    Now you will be able to identify logs that are from previous requests. Your sw is not making extra request, just the console is keeping old logs.


    To fix it, do right click inside the console and click on clear console history.

    Hope this help.

    0 讨论(0)
提交回复
热议问题