1. Once serive worker is registered, the first time we go to the app, we cannot see the logs from servcie works. Any only refersh it second time, then we able to see the logs.

  2. Once we change service worker, it doesn't seem that we have change it.

The No1. is because, service worker only take control after it is loaded. But the first time we go to the page, service worker actually is not there, because, the browser need to fetch our assets, css, and Javascript fiels which include our sw.js. So that's why the first time we go to page, we didn't see the logs. But after we refresh the page, the sw.js is already cached. So the service worker can control from now on.

The No2. is because, once we change the code, it will check with service worker and if it is changed, it will become next version of serive worker. BUT it doesn't take control, it WATIS. It won't take control unitl all page use current version are gone. And a refresh doens't help, it because a overlap bewteen window client. Only you close the current page or naviagte to a page that isn't controlled by current service worker. When it does that, the new version of servie worker will take control.

So if you change the code a little bit:

self.addEventListener('fetch', function(event) {
console.log("yo ",event.request);
});

And then close the current page, then open it again, you will see the new logs come out:

[PWA] 2. Service worker life cycle的更多相关文章

  1. [PWA] 9. Service worker registerion && service work's props, methods and listeners

    In some rare cases, you need to ask user to refresh the browsser to update the version. Maybe becaus ...

  2. 转《service worker在移动端H5项目的应用》

    1. PWA和Service Worker的关系 PWA (Progressive Web Apps) 不是一项技术,也不是一个框架,我们可以把她理解为一种模式,一种通过应用一些技术将 Web App ...

  3. service worker在移动端H5项目的应用

    1. PWA和Service Worker的关系 PWA (Progressive Web Apps) 不是一项技术,也不是一个框架,我们可以把她理解为一种模式,一种通过应用一些技术将 Web App ...

  4. [PWA] 1. Intro to Service worker

    Service worker stays between our browser and noetwork requests. It can help to fetch data from cache ...

  5. [PWA] Show Notifications when a Service Worker is Installed or Updated

    Service Workers get installed and activated in the background, but until we reload the page they don ...

  6. PWA - service worker - Workbox(未完)

    Get Started(开始) 只有get请求才能cache缓存吗? Create and Register a Service Worker File(创建和注册 Service Worker) B ...

  7. Service Worker和HTTP缓存

    很多人,包括我自己,初看Service Worker多一个Cache Storage的时候,就感觉跟HTTP长缓存没什么区别. 例如大家讲的最多的Service Worker能让网页离线使用,但熟悉H ...

  8. Service Worker

    Service Worker 随着前端快速发展,应用的性能已经变得至关重要,关于这一点大佬做了很多统计.你可以去看看. 如何降低一个页面的网络请求成本从而缩短页面加载资源的时间并降低用户可感知的延时是 ...

  9. 浏览器缓存和Service Worker

    浏览器缓存和Service Worker @billshooting 2018-05-06 字数 6175 Follow me on Github 标签: BOM 1. 传统的HTTP浏览器缓存策略 ...

随机推荐

  1. gSoap实现ONVIF中xsd__anyType到具体结构类型的转换

    上一篇文章已经粗略计划要讨论gsoap关于序列化/解析编程. 本文则阐述一下关于gsoap生成代码的一些重要特征方法及使用.如题,下我们从ONVIF生成的C码中,挑选简单的一个类型来试验一下与xsd_ ...

  2. MySql数据库3【优化3】缓存设置的优化

    1.表缓存 相关参数: table_open_cache 指定表缓存的大小.每当MySQL访问一个表时,如果在表缓冲区中还有空间,该表就被打开并放入其中,这样可以更快地访问表内容.通过检查峰值时间的状 ...

  3. PM加油站

    老郭讲述深航CSM 1.需求有遗漏,人员水平不足:加班导致人员流失:但是这样,客户后来还是好评,并且项目被评为深航的标杆项目:老郭也是被指定为未来项目的项目经理:--!我想起了古时候的一句话:功夫在诗 ...

  4. Unity3d Material(材质) 无缝拼接

    Unity3d Material(材质) Edit by @灰太龙 在做一个项目的过程中,遇到动态切换壁纸的功能,问题点在无缝拼接! 那我们先查查Unity3d 中的材质球,里面有个参数 Tiling ...

  5. cf B. Number Busters

    http://codeforces.com/contest/382/problem/B 题意:给你Aa,b,w,x,c,然后每经过1秒,c=c-1;  如果b>=x,b=b-x;否则 a=a-1 ...

  6. C++不能中断构造函数来拒绝产生对象(在构造和析构中抛出异常)

    这是我的感觉,具体需要研究一下- 找到一篇文章:在构造和析构中抛出异常 测试验证在类构造和析构中抛出异常, 是否会调用该类析构. 如果在一个类成员函数中抛异常, 可以进入该类的析构函数. /// @f ...

  7. php socket 通信

    Socket扩展是基于流行的BSD sockets,实现了和socket通讯功能的底层接口,它可以和客户端一样当做一个socket服务器. 想了解更通用的客户端socket接口,请看 stream_s ...

  8. 【HDOJ】2319 Card Trick

    水题,STL双端队列. /* 2319 */ #include <iostream> #include <cstdio> #include <cstring> #i ...

  9. pygame安装

    进入这个网站 http://www.pygame.org/wiki/Compilation 可以选择不同系统的安装方法 其中ubuntu的安装命令是 #这是python .X #install dep ...

  10. Seasar2框架:AOP

    Seasar2是由日本人开发的一个框架.它通过自己定义的规约,很大程度上地减少了设定代码.但是由于这个原因,导致了框架学习初期会有比较大的跨越. AOP例子: Greeting.java packag ...