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 beeng revisioned, such as URLs like /styles/example.a8f5f1.css
, since they can be cached for long periods of time.
CacheOnly
An implementation of a cache-only request strategy.
This class is useful if you want to take advantage of any Workbox plugins.
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.
NetworkOnly
An implementation of a network-only request strategy.
This class is useful if you want to take advantage of any Workbox plugins.
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.
Methods
cacheFirst
cacheFirst(options)
Parameter |
|
---|---|
options |
StrategyOptions |
cacheOnly
cacheOnly(options)
Parameter |
|
---|---|
options |
StrategyOptions |
networkFirst
networkFirst(options)
Parameter |
|
---|---|
options |
StrategyOptions |
networkOnly
networkOnly(options)
Parameter |
|
---|---|
options |
StrategyOptions |
staleWhileRevalidate
staleWhileRevalidate(options)
Parameter |
|
---|---|
options |
StrategyOptions |
Abstract type
StrategyOptions
Object
Properties
Parameter |
|||||||
---|---|---|---|---|---|---|---|
cacheName |
String Name of cache to use for caching (both lookup and updating). |
||||||
cacheExpiration |
Object Defining this object will add a cache expiration plugins to this strategy. Values in
|