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
{ | |
"name": "demo", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"build": "webpack" | |
}, | |
"keywords": [], | |
"author": "", |
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
export class FallbackOnErrorPlugin { | |
constructor(fallbackURL) { | |
this.fallbackURL = fallbackURL; | |
} | |
// This is called whenever there's a network response, | |
// but we want special behavior for non-2xx statuses. | |
fetchDidSucceed({response}) { | |
if (response.ok) { | |
// If it's a 2xx, it can be used as-is. |
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
import {RouteHandlerCallbackOptions} from 'workbox-core/types'; | |
import {CacheFirst, NetworkFirst} from 'workbox-strategies'; | |
import {registerRoute} from 'workbox-routing'; | |
// Borrowed from https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook#cache-and-network-race | |
function promiseAny(promises: Array<Promise<Response>>): Promise<Response> { | |
return new Promise((resolve, reject) => { | |
promises = promises.map(p => Promise.resolve(p)); | |
promises.forEach(p => p.then(resolve)); | |
promises.reduce((a, b) => a.catch(() => b)) |
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
async function totalCacheSize() { | |
let size = 0; | |
const cacheNames = await caches.keys(); | |
for (const cacheName of cacheNames) { | |
const cache = await caches.open(cacheName); | |
const cachedRequests = await cache.keys(); | |
for (const cachedRequest of cachedRequests) { | |
const cachedResponse = await cache.match(cachedRequest); | |
const responseBlob = await cachedResponse.blob(); | |
size += responseBlob.size; |
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
import {CacheFirst, NetworkOnly} from 'workbox-strategies'; | |
import {cacheNames} from 'workbox-core'; | |
import {cleanupOutdatedCaches, getCacheKeyForURL, precacheAndRoute} from 'workbox-precaching'; | |
import {ExpirationPlugin} from 'workbox-expiration'; | |
import {initialize as initializeOfflineAnalytics} from 'workbox-google-analytics'; | |
import {registerRoute, setCatchHandler} from 'workbox-routing'; | |
import {RouteHandlerCallbackOptions} from 'workbox-core/types'; | |
import {skipWaiting} from 'workbox-core'; | |
import nunjucks from 'nunjucks/browser/nunjucks'; |
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
import {registerRoute} from 'workbox-routing/registerRoute'; | |
registerRoute('/path', yourHandlerCode); |
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
// Add any other logic here as needed. | |
import { CacheableResponsePlugin } from 'workbox-cacheable-response/CacheableResponsePlugin'; | |
import { CacheFirst } from 'workbox-strategies/CacheFirst'; | |
import { createHandlerForURL } from 'workbox-precaching/createHandlerForURL'; | |
import { ExpirationPlugin } from 'workbox-expiration/ExpirationPlugin'; | |
import { NavigationRoute } from 'workbox-routing/NavigationRoute'; | |
import { precacheAndRoute } from 'workbox-precaching/precacheAndRoute'; | |
import { registerRoute } from 'workbox-routing/registerRoute'; |
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
addEventListener('install', (event) => ; { | |
event.waitUntil(async function() { | |
const cache = await caches.open('static-v1'); | |
await cache.addAll(['offline.html', 'styles.css']); | |
}()); | |
}); | |
// See https://developers.google.com/web/updates/2017/02/navigation-preload#activating_navigation_preload | |
addEventListener('activate', event => { | |
event.waitUntil(async function() { |
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
#!/bin/sh | |
echo "Beginning Camino Nightly Download: `date`" >> /Users/jeff/Documents/Camino/log.txt | |
echo "Changing to download folder" >> /Users/jeff/Documents/Camino/log.txt | |
cd ~/Documents/Camino | |
echo "pwd is: `pwd`" >> /Users/jeff/Documents/Camino/log.txt | |
echo "Downloading Camino: `date`" >> /Users/jeff/Documents/Camino/log.txt |
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
async function findOpaqueResponses() { | |
const cacheNames = await caches.keys(); | |
const urlsResultingInAnOpaqueResponse = []; | |
for (const cacheName of cacheNames) { | |
const cache = await caches.open(cacheName); | |
const requests = await cache.keys(); | |
for (const request of requests) { | |
const response = await cache.match(request); | |
if (response.status === 0) { | |
urlsResultingInAnOpaqueResponse.push(request.url); |
NewerOlder