-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
7,727 additions
and
7,146 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
nodeLinker: node-modules | ||
compressionLevel: mixed | ||
|
||
enableGlobalCache: false | ||
|
||
plugins: | ||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs | ||
spec: "@yarnpkg/plugin-interactive-tools" | ||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-3.5.0.cjs | ||
yarnPath: .yarn/releases/yarn-4.1.0.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,114 @@ | ||
// THIS FILE SHOULD NOT BE VERSION CONTROLLED | ||
const options = {"workboxURL":"https://cdn.jsdelivr.net/npm/workbox-cdn@5.1.4/workbox/workbox-sw.js","importScripts":[],"config":{"debug":false},"cacheOptions":{"cacheId":"nuxt-shopify-docs-prod","directoryIndex":"/","revision":"uNrks38L0Iyz"},"clientsClaim":true,"skipWaiting":true,"cleanupOutdatedCaches":true,"offlineAnalytics":false,"preCaching":[{"revision":"uNrks38L0Iyz","url":"/?standalone=true"}],"runtimeCaching":[{"urlPattern":"/_nuxt/","handler":"CacheFirst","method":"GET","strategyPlugins":[]},{"urlPattern":"/","handler":"NetworkFirst","method":"GET","strategyPlugins":[]}],"offlinePage":null,"pagesURLPattern":"/","offlineStrategy":"NetworkFirst"} | ||
|
||
// https://github.com/NekR/self-destroying-sw | ||
importScripts(...[options.workboxURL, ...options.importScripts]) | ||
|
||
self.addEventListener('install', function (e) { | ||
self.skipWaiting() | ||
}) | ||
initWorkbox(workbox, options) | ||
workboxExtensions(workbox, options) | ||
precacheAssets(workbox, options) | ||
cachingExtensions(workbox, options) | ||
runtimeCaching(workbox, options) | ||
offlinePage(workbox, options) | ||
routingExtensions(workbox, options) | ||
|
||
self.addEventListener('activate', function (e) { | ||
self.registration.unregister() | ||
.then(function () { | ||
return self.clients.matchAll() | ||
}) | ||
.then(function (clients) { | ||
clients.forEach(client => client.navigate(client.url)) | ||
function getProp(obj, prop) { | ||
return prop.split('.').reduce((p, c) => p[c], obj) | ||
} | ||
|
||
function initWorkbox(workbox, options) { | ||
if (options.config) { | ||
// Set workbox config | ||
workbox.setConfig(options.config) | ||
} | ||
|
||
if (options.cacheNames) { | ||
// Set workbox cache names | ||
workbox.core.setCacheNameDetails(options.cacheNames) | ||
} | ||
|
||
if (options.clientsClaim) { | ||
// Start controlling any existing clients as soon as it activates | ||
workbox.core.clientsClaim() | ||
} | ||
|
||
if (options.skipWaiting) { | ||
workbox.core.skipWaiting() | ||
} | ||
|
||
if (options.cleanupOutdatedCaches) { | ||
workbox.precaching.cleanupOutdatedCaches() | ||
} | ||
|
||
if (options.offlineAnalytics) { | ||
// Enable offline Google Analytics tracking | ||
workbox.googleAnalytics.initialize() | ||
} | ||
} | ||
|
||
function precacheAssets(workbox, options) { | ||
if (options.preCaching.length) { | ||
workbox.precaching.precacheAndRoute(options.preCaching, options.cacheOptions) | ||
} | ||
} | ||
|
||
|
||
function runtimeCaching(workbox, options) { | ||
const requestInterceptor = { | ||
requestWillFetch({ request }) { | ||
if (request.cache === 'only-if-cached' && request.mode === 'no-cors') { | ||
return new Request(request.url, { ...request, cache: 'default', mode: 'no-cors' }) | ||
} | ||
return request | ||
}, | ||
fetchDidFail(ctx) { | ||
ctx.error.message = | ||
'[workbox] Network request for ' + ctx.request.url + ' threw an error: ' + ctx.error.message | ||
console.error(ctx.error, 'Details:', ctx) | ||
}, | ||
handlerDidError(ctx) { | ||
ctx.error.message = | ||
`[workbox] Network handler threw an error: ` + ctx.error.message | ||
console.error(ctx.error, 'Details:', ctx) | ||
return null | ||
} | ||
} | ||
|
||
for (const entry of options.runtimeCaching) { | ||
const urlPattern = new RegExp(entry.urlPattern) | ||
const method = entry.method || 'GET' | ||
|
||
const plugins = (entry.strategyPlugins || []) | ||
.map(p => new (getProp(workbox, p.use))(...p.config)) | ||
|
||
plugins.unshift(requestInterceptor) | ||
|
||
const strategyOptions = { ...entry.strategyOptions, plugins } | ||
|
||
const strategy = new workbox.strategies[entry.handler](strategyOptions) | ||
|
||
workbox.routing.registerRoute(urlPattern, strategy, method) | ||
} | ||
} | ||
|
||
function offlinePage(workbox, options) { | ||
if (options.offlinePage) { | ||
// Register router handler for offlinePage | ||
workbox.routing.registerRoute(new RegExp(options.pagesURLPattern), ({ request, event }) => { | ||
const strategy = new workbox.strategies[options.offlineStrategy] | ||
return strategy | ||
.handle({ request, event }) | ||
.catch(() => caches.match(options.offlinePage)) | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
function workboxExtensions(workbox, options) { | ||
|
||
} | ||
|
||
function cachingExtensions(workbox, options) { | ||
|
||
} | ||
|
||
function routingExtensions(workbox, options) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,5 +71,5 @@ | |
"ts-node": "10.9.2", | ||
"typescript": "5.3.3" | ||
}, | ||
"packageManager": "yarn@3.5.0" | ||
"packageManager": "yarn@4.1.0" | ||
} |
Oops, something went wrong.