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 '@edgio/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 '@edgio/prefetch/sw'
 import { precacheAndRoute } from 'workbox-precaching'

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

 new Prefetcher().route()

Hierarchy

  • Prefetcher

Index

Constructors

constructor

Methods

cache

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

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

    Returns this

getRouteConfigsFromManifest

  • getRouteConfigsFromManifest(): { convertToGet: any; criteriaPath: any; edgeMaxAgeSeconds: any; isPartialPathRoute: true; key: any; maxAgeSeconds: any; method: any; pattern: any; prefetchUpstreamRequests: any; returnsResponse: any }[]
  • Returns { convertToGet: any; criteriaPath: any; edgeMaxAgeSeconds: any; isPartialPathRoute: true; key: any; maxAgeSeconds: any; method: any; pattern: any; prefetchUpstreamRequests: any; returnsResponse: any }[]

route

  • route(): this
  • 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 browser.serviceWorkerSeconds defined in its cache setting or if the request is a prefetch.

    Returns this

transformHTTPMethod

  • transformHTTPMethod(method: HTTPMethod): "DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT" | undefined
  • Transform method from HTTPMethod type to uppercase HTTPMethod type from workbox the way typescript tolerates

    Parameters

    • method: HTTPMethod

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

Generated using TypeDoc