OLD | NEW |
(Empty) | |
| 1 # Platinum Service Worker Elements |
| 2 A set of Polymer elements that simplify service worker registration and caching,
powered by the |
| 3 [`sw-toolbox` library](https://github.com/googlechrome/sw-toolbox). |
| 4 Full documentation is available at https://PolymerElements.github.io/platinum-sw
/index.html |
| 5 |
| 6 # Considerations |
| 7 |
| 8 ## Top-level `sw-import.js` |
| 9 While `<platinum-sw-register>` abstracts away many of the details of working wit
h service workers, |
| 10 there is one specific requirement that developers must fulfill: it needs to regi
ster a JavaScript file |
| 11 located at the top-level of your site's web root. (Details behind this requireme
nt can be found in |
| 12 the service worker specification [issue tracker](https://github.com/slightlyoff/
ServiceWorker/issues/468#issuecomment-60276779).) |
| 13 |
| 14 In order to use `<platinum-sw-register>`, it's recommended that you create a `sw
-import.js` file in |
| 15 your site's web root. The file's only contents should be |
| 16 |
| 17 importScripts('bower_components/platinum-sw/service-worker.js'); |
| 18 |
| 19 You can adjust the path to `service-worker.js` if your project has its Polymer e
lements |
| 20 installed somewhere other than `bower_components/`. |
| 21 |
| 22 If you have multiple subdirectories worth of pages on your site, it's recommend
that you include the |
| 23 `<platinum-sw-register>` element on a top-level entry page that all visitors wil
l access first; once |
| 24 they visit the top-level page and the service worker is registered, it will auto
matically apply to |
| 25 all sub-pages, which will fall under its |
| 26 [scope](https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.ht
ml#service-worker-registration-scope). |
| 27 |
| 28 ## `cacheOnly` & `cacheFirst` `defaultCacheStrategy` Considered Harmful |
| 29 The [`sw-toolbox` library](https://github.com/googlechrome/sw-toolbox), |
| 30 which `<platinum-sw-cache>` is built on, supports a number of |
| 31 [caching strategies](https://github.com/googlechrome/sw-toolbox#built-in-handler
s). |
| 32 Two of them, `cacheOnly` and `cacheFirst`, are strongly discouraged to be used a
s the `defaultCacheStrategy` |
| 33 for `<platinum-sw-cache>`. With both of those strategies, all HTTP requests, inc
luding requests for |
| 34 the page which contains the `<platinum-sw-cache>` element, are served directly f
rom the [Cache Storage |
| 35 API](https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#
cache-objects) without |
| 36 first consulting the network for a fresh copy. Once the copy of the host page is
cached, |
| 37 it's extremely difficult to change the configuration of the service worker (sinc
e the configuration |
| 38 depends on the page's contents), and developers could find themselves deploying
sites that can never |
| 39 update. |
| 40 |
| 41 In a future release of `<platinum-sw-cache>`, using `cacheOnly` and `cacheFirst`
as `defaultCacheStrategy` |
| 42 may lead to an explicit error condition, but for the meantime, please consider a
more reasonable default |
| 43 (like `networkFirst`). |
OLD | NEW |