折腾小记 – Service Worker

0 序

退役了,文化课了。于是每天写代码的时间连 20min 都没有了。

但我还是想写!那就整点乐子吧

1 Service Worker

The service worker is designed first to redress this balance by providing a Web Worker context, which can be started by a runtime when navigations are about to occur. This event-driven worker is registered against an origin and a path (or pattern), meaning it can be consulted when navigations occur to that location. Events that correspond to network requests are dispatched to the worker and the responses generated by the worker may override default network stack behavior. This puts the service worker, conceptually, between the network and a document renderer, allowing the service worker to provide content for documents, even while offline.

https://www.w3.org/TR/service-workers/#motivations

翻译一下就是

Service Worker 提供了一种在请求前进行处理的 Web Worker。开发者可以通过此技术来拦截并修改每一个请求,并通过访问缓存等方式实现在网络较差甚至离线情况下对网页的访问。

Continue reading “折腾小记 – Service Worker”