프로젝트
GitHub에서 보기
lyzadanger/pragmatist-service-worker
소개
Pragmatist's Guide to Service Worker
학습 및 교육측정된 스타 증가
- in 24h
- 0
- in 7 days
- -1
- in 15 days
- -1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalPragmatist's Guide to Service Workers
In this repository, you'll find code examples to illustrate the Pragmatist's Guide presentation, given at Smashing Conference, Freiburg, September 2016.
Install
Clone this repository, then:
npm install
To run a local web server and see the examples in action, run:
npm start
You'll want to use a browser that supports Service Worker; I use Chrome but SW is also supported in Firefox and Opera to differing extents.
Note: These examples, run locally, rely on the localhost exception to the SSL/TLS requirement for Service Workers.
Examples
- Mission 1: Offline message — Respond to
navigationrequests (i.e. requests for HTML documents). Try to fetch from the network, but if that fails, return aResponseobject that emulates a simple web page with anOh, dearmessage. - Mission 2: Offline page — Same as before, but instead of returning a self-made Response on fetch failure, cache an offline HTML page during the
installphase and return that upon fetch failure. - Mission 3: Network strategies — Respond to fetches for content (HTML) and static assets (images) differently. Use a network-first strategy for content and a cache-first strategy for images.
- Mission 4: Application shell — During the
installphase, cache a bunch of static assets that we consider to be our application's "shell". Respond to fetches and look in the cache first for requests for those assets. Once the service worker is installed, you can go offline and continue to "request clouds" (images of clouds). - Mission 5: Cache naming and cleanup — Use cache-prefixing to manage versioning of a service worker and, during the
activatephase, clean up (old) caches that don't match the new cache prefix. To version-bump, you'd want to change thecachePrefixvalue. - Mission 6: Fancypants — Add a fallback offline image and use a JSON file as a source of URLs to pre-cache during
install.
관련 프로젝트 살펴보기
불러오는 중…