Chrome Dev Summit is back! Visit goo.gle/cds2021 to secure your spot in workshops, office hours and learning lounges!

Module: workbox-recipes

Methods

googleFontsCache

static

googleFontsCache(options)

An implementation of the Google fonts caching recipe

Parameter

options

Optional

Object

Values in options have the following properties:

Parameter

cachePrefix

Optional

string

Cache prefix for caching stylesheets and webfonts. Defaults to google-fonts

maxAgeSeconds

Optional

number

Maximum age, in seconds, that font entries will be cached for. Defaults to 1 year

maxEntries

Optional

number

Maximum number of fonts that will be cached. Defaults to 30

imageCache

static

imageCache(options)

An implementation of the image caching recipe

Parameter

options

Optional

Object

Values in options have the following properties:

Parameter

cacheName

Optional

string

Name for cache. Defaults to images

matchCallback

Optional

RouteMatchCallback

Workbox callback function to call to match to. Defaults to request.destination === 'image';

maxAgeSeconds

Optional

number

Maximum age, in seconds, that font entries will be cached for. Defaults to 30 days

maxEntries

Optional

number

Maximum number of images that will be cached. Defaults to 60

plugins

Optional

Array of WorkboxPlugin

Additional plugins to use for this recipe

warmCache

Optional

Array of string

Paths to call to use to warm this cache

offlineFallback

static

offlineFallback(options)

An implementation of the comprehensive fallbacks recipe. Be sure to include the fallbacks in your precache injection

Parameter

options

Optional

Object

Values in options have the following properties:

Parameter

pageFallback

Optional

string

Precache name to match for pag fallbacks. Defaults to offline.html

imageFallback

Optional

string

Precache name to match for image fallbacks.

fontFallback

Optional

string

Precache name to match for font fallbacks.

pageCache

static

pageCache(options)

An implementation of a page caching recipe with a network timeout

Parameter

options

Optional

Object

Values in options have the following properties:

Parameter

cacheName

Optional

string

Name for cache. Defaults to pages

matchCallback

Optional

RouteMatchCallback

Workbox callback function to call to match to. Defaults to request.mode === 'navigate';

networkTimoutSeconds

Optional

number

Maximum amount of time, in seconds, to wait on the network before falling back to cache. Defaults to 3

plugins

Optional

Array of WorkboxPlugin

Additional plugins to use for this recipe

warmCache

Optional

Array of string

Paths to call to use to warm this cache

staticResourceCache

static

staticResourceCache(options)

An implementation of the CSS and JavaScript files recipe

Parameter

options

Optional

Object

Values in options have the following properties:

Parameter

cacheName

Optional

string

Name for cache. Defaults to static-resources

matchCallback

Optional

RouteMatchCallback

Workbox callback function to call to match to. Defaults to request.destination === 'style' || request.destination === 'script' || request.destination === 'worker';

plugins

Optional

Array of WorkboxPlugin

Additional plugins to use for this recipe

warmCache

Optional

Array of string

Paths to call to use to warm this cache

warmStrategyCache

static

warmStrategyCache(options)

Parameter

options

Object

Values in options have the following properties:

Parameter

urls

Array of string

Paths to warm the strategy's cache with

strategy

Strategy

Strategy to use