CacheOnly extends module:workbox-runtime-caching.Handler

An implementation of a cache-only request strategy.

The advantage to using this versus directly calling caches.match() is that it will use the cache configuration and trigger the plugins defined in the underlying RequestWrapper which accounts for behaviors like cache expiration.

Example

// Set up a route to match any requests made for URLs that end in .txt.
// The requests are handled with a cache-only strategy.
const route = new workbox.routing.RegExpRoute({
  regExp: /\.txt$/,
  handler: new workbox.runtimeCaching.CacheOnly(),
});

const router = new workbox.routing.Router();
router.registerRoute({route});

Instance Methods

this.handle(input) Promise.<Response>

The handle method will be called by the Route class when a route matches a request.

Parameters
input Object
Properties
event FetchEvent

The event that triggered the service worker's fetch handler.

Returns Promise.<Response>

The response from the cache or null.