workbox-runtime-caching. NetworkFirst
An implementation of a network first request strategy.
By default, NetworkFirst
will cache responses with a 200 status code as well as opaque responses (responses from cross-origin servers which don't support
CORS). You can override this default by passing in a RequestWrapper
that includes an appropriately-configured
CacheableResponsePlugin
.
Constructor
NetworkFirst
new NetworkFirst(input)
Constructor for a new NetworkFirst instance.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
input |
Object Values in
|
Example
// Set up a route to match any requests made for URLs that end in .txt.
// The requests are handled with a network-first strategy.
const route = new workbox.routing.RegExpRoute({
regExp: /\.txt$/,
handler: new workbox.runtimeCaching.NetworkFirst(),
});
const router = new workbox.routing.Router();
router.registerRoute({route});
Method
handle
handle(input) returns Promise containing Response
The handle method will be called by the Route class when a route matches a request.
Parameter |
|||||
---|---|---|---|---|---|
input |
Object Values in
|
- Returns
-
Promise containing Response
The response from the network, or if that's not available, a previously cached response.