Constants
Exported values
serwist
exports a few constants that you can make use of for more convenience. This includes:
BROADCAST_UPDATE_DEFAULT_HEADERS
What: the default list of headers to check.
How to use:
import {
responsesAreSame ,BROADCAST_UPDATE_DEFAULT_HEADERS } from "serwist"; declare constself :ServiceWorkerGlobalScope ; constcacheName = "api-cache"; constrequest = newRequest ("https://example.com/api"); constcache = awaitcaches .open (cacheName ); constoldResponse = awaitcache .match (request ); constnewResponse = awaitfetch (request ); if (oldResponse && !responsesAreSame (oldResponse ,newResponse ,BROADCAST_UPDATE_DEFAULT_HEADERS )) { constwindows = awaitself .clients .matchAll ({type : "window" }); for (constwin ofwindows ) {win .postMessage ({type : "CACHE_UPDATED",message : "Update now!" }); } }