Handles prefetching and caching in the service worker. Responses are cached based on the service_worker_max_age feature or equivalent browser.serviceWorkerSeconds cache setting in your rules.

Example routes.js

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

module.exports = new Router()
.match('/some/path', {
caching: {
max_age: "1d",
service_worker_max_age: "1h"
}
})
.match('/another/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 '@edgio/prefetch/sw'
import { precacheAndRoute } from 'workbox-precaching'

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

new Prefetcher().route()

Hierarchy

  • default

Constructors

Methods

  • Parameters

    • pattern: RegExp
    • maxAgeSeconds: number = ...

    Returns default

  • Adds a fetch event listener that serves content from the browser 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 `service_worker_max_age' feature defined or if the request is a prefetch.

    Returns default

  • Transform method from HTTPMethod type to uppercase HTTPMethod type from workbox the way typescript tolerates

    Returns

    Parameters

    • method: HTTPMethod

    Returns undefined | "DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT"

Generated using TypeDoc