workbox. strategies
There are common caching strategies that most service workers will need and use. This module provides simple implementations of these strategies.
Classes
CacheFirst
An implementation of a cache-first request strategy.
A cache first strategy is useful for assets that have been revisioned, such as URLs like /styles/example.a8f5f1.css
, since they can be cached for long periods of time.
If the network request fails, and there is no cache match, this will throw a WorkboxError
exception.
CacheOnly
An implementation of a cache-only request strategy.
This class is useful if you want to take advantage of any Workbox plugins.
If there is no cache match, this will throw a WorkboxError
exception.
NetworkFirst
An implementation of a network first request strategy.
By default, this strategy will cache responses with a 200 status code as well as opaque responses. Opaque responses are are cross-origin requests where the response doesn't support CORS.
If the network request fails, and there is no cache match, this will throw a WorkboxError
exception.
NetworkOnly
An implementation of a network-only request strategy.
This class is useful if you want to take advantage of any Workbox plugins.
If the network request fails, this will throw a WorkboxError
exception.
StaleWhileRevalidate
An implementation of a stale-while-revalidate request strategy.
Resources are requested from both the cache and the network in parallel. The strategy will respond with the cached version if available, otherwise wait for the network response. The cache is updated with the network response with each successful request.
By default, this strategy will cache responses with a 200 status code as well as opaque responses. Opaque responses are are cross-origin requests where the response doesn't support CORS.
If the network request fails, and there is no cache match, this will throw a WorkboxError
exception.
Methods
cacheFirst
cacheFirst(options)
Parameter |
|
---|---|
options |
Object See the workbox.strategies.CacheFirst constructor for more info. |
- Deprecated
- since v4.0.0
cacheOnly
cacheOnly(options)
Parameter |
|
---|---|
options |
Object See the workbox.strategies.CacheOnly constructor for more info. |
- Deprecated
- since v4.0.0
networkFirst
networkFirst(options)
Parameter |
|
---|---|
options |
Object See the workbox.strategies.NetworkFirst constructor for more info. |
- Deprecated
- since v4.0.0
networkOnly
networkOnly(options)
Parameter |
|
---|---|
options |
Object See the workbox.strategies.NetworkOnly constructor for more info. |
- Deprecated
- since v4.0.0
staleWhileRevalidate
staleWhileRevalidate(options)
Parameter |
|
---|---|
options |
Object See the workbox.strategies.StaleWhileRevalidate constructor for more info. |
- Deprecated
- since v4.0.0