Options
All
  • Public
  • Public/Protected
  • All
Menu

Handles prefetching and caching in the the service worker. Responses are cached based on the browser.serviceWorkerSeconds cache setting in your routes.

Example routes.js

 import { Router } from '@xdn/core/router'

 module.exports = new Router()
   .match('/some/path', ({ cache }) => {
     cache({
       edge: {
         maxAgeSeconds: 60 * 60 * 24 // one day
       },
       browser: {
         serviceWorkerSeconds: 60 * 60 // one hour
       }
     })
   })

Example Service Worker

 import { skipWaiting, clientsClaim } from 'workbox-core'
 import { Prefetcher } from '@xdn/prefetch/sw'
 import { precacheAndRoute } from 'workbox-precaching'

 skipWaiting()
 clientsClaim()
 precacheAndRoute(self.__WB_MANIFEST || [])

 new Prefetcher().route()

Hierarchy

  • Prefetcher

Index

Constructors

Methods

Constructors

constructor

Methods

cache

  • cache(pattern: RegExp, maxAgeSeconds?: number): this
  • Parameters

    • pattern: RegExp
    • Default value maxAgeSeconds: number = 60 * 60 * 24

    Returns this

route

  • route(): this
  • Adds a fetch event listener that serves content from the cache when available. When a request is not in the cache, it will be fetched from the network and added to the cache if the route has browser.serviceWorkerSeconds defined in its cache setting.

    Returns this

Generated using TypeDoc