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 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.
Strategy
An abstract base class that all other strategy classes must extend from:
StrategyHandler
A class created every time a Strategy instance instance calls
handle() or
handleAll() that wraps all fetch and
cache actions around plugin callbacks and keeps track of when the strategy
is "done" (i.e. all added event.waitUntil()
promises have resolved).