worker.js |
|
---|---|
First import the offliner library. This import exports the namespaces |
|
By convention, fetchers are put inside the |
|
Sources are in the |
|
And updaters in the |
|
You can create an offliner instance using |
|
Offliner provides with a configurable strategy to prefetch resources. Each resource is an object with a type and other data. Each fetcher has a type. Offliner gathers all the resources with the same type and feeds the fetcher with the matching type of those resources. |
|
You register a fetcher by calling |
|
Then provide an array (you can pass a solely item as well) of resources
by using |
|
Offliner has a plugable fetch strategy based on fallbacks. When a resource is fetched, it traverse all the source pipeline until one is able to provide a response. If the source returns a rejected promise or throws an exception, the request pass to the next source until reaching the end of the pipeline. |
|
You call |
|
Order is important and so, |
|
You can use |
|
Last but not least, Offliner offers a generic update strategy. It is based on the following steps: 1. Get the latest version. [hook] 2. Determine if it is a new version. [hook] 3. Prepare a new offline cache. 4. Populate the new cache updating the old one. [hook] 5. After the service worker is stopped and before the next first fetch, activate the new cache. As you can see, there are three [hook] marks indicating which steps can be customized. These steps must be provided by the update implementation. |
|
You call |
|
With |
|
Lastly, use |
|