CacheFirst extends module:workbox-runtime-caching.Handler

An implementation of a cache-first request strategy.

The important thing to note with this caching strategy is that once a response is cached, it will not be updated. This is useful for assets that are revisioned since it caches the asset long term and doesn't waste the user's data.


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

const router = new workbox.routing.Router();

Instance Methods

this.handle(input) Promise.<Response>

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

input Object
event FetchEvent

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

Returns Promise.<Response>

The response, either from the cache, or if that isn't available, the request will be made on the the network and the result will be cached for future use.