mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-19 03:59:09 +00:00
Rollup build
This commit is contained in:
@@ -1,43 +1,50 @@
|
||||
import {
|
||||
cacheOrNetworkAndCache, cleanupCache, cacheOrNetwork, cacheBasics, cacheAdditionalProcessors,
|
||||
cacheOrNetworkAndCache,
|
||||
cleanupCache,
|
||||
cacheOrNetwork,
|
||||
cacheBasics,
|
||||
cacheAdditionalProcessors,
|
||||
serveShareTarget,
|
||||
} from './util';
|
||||
import { get } from 'idb-keyval';
|
||||
|
||||
// Give TypeScript the correct global.
|
||||
declare var self: ServiceWorkerGlobalScope;
|
||||
// This is populated by webpack.
|
||||
declare var BUILD_ASSETS: string[];
|
||||
|
||||
const versionedCache = 'static-' + VERSION;
|
||||
const dynamicCache = 'dynamic';
|
||||
const expectedCaches = [versionedCache, dynamicCache];
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
event.waitUntil(async function () {
|
||||
const promises = [];
|
||||
promises.push(cacheBasics(versionedCache, BUILD_ASSETS));
|
||||
event.waitUntil(
|
||||
(async function () {
|
||||
const promises = [];
|
||||
promises.push(cacheBasics(versionedCache, ASSETS));
|
||||
|
||||
// If the user has already interacted with the app, update the codecs too.
|
||||
if (await get('user-interacted')) {
|
||||
promises.push(cacheAdditionalProcessors(versionedCache, BUILD_ASSETS));
|
||||
}
|
||||
// If the user has already interacted with the app, update the codecs too.
|
||||
if (await get('user-interacted')) {
|
||||
promises.push(cacheAdditionalProcessors(versionedCache, ASSETS));
|
||||
}
|
||||
|
||||
await Promise.all(promises);
|
||||
}());
|
||||
await Promise.all(promises);
|
||||
})(),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
self.clients.claim();
|
||||
|
||||
event.waitUntil(async function () {
|
||||
// Remove old caches.
|
||||
const promises = (await caches.keys()).map((cacheName) => {
|
||||
if (!expectedCaches.includes(cacheName)) return caches.delete(cacheName);
|
||||
});
|
||||
event.waitUntil(
|
||||
(async function () {
|
||||
// Remove old caches.
|
||||
const promises = (await caches.keys()).map((cacheName) => {
|
||||
if (!expectedCaches.includes(cacheName))
|
||||
return caches.delete(cacheName);
|
||||
});
|
||||
|
||||
await Promise.all<any>(promises);
|
||||
}());
|
||||
await Promise.all<any>(promises);
|
||||
})(),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
@@ -58,9 +65,9 @@ self.addEventListener('fetch', (event) => {
|
||||
// We only care about GET from here on in.
|
||||
if (event.request.method !== 'GET') return;
|
||||
|
||||
if (url.pathname.startsWith('/demo-') || url.pathname.startsWith('/wc-polyfill')) {
|
||||
if (url.pathname.startsWith('/c/demo-')) {
|
||||
cacheOrNetworkAndCache(event, dynamicCache);
|
||||
cleanupCache(event, dynamicCache, BUILD_ASSETS);
|
||||
cleanupCache(event, dynamicCache, ASSETS);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -70,7 +77,7 @@ self.addEventListener('fetch', (event) => {
|
||||
self.addEventListener('message', (event) => {
|
||||
switch (event.data) {
|
||||
case 'cache-all':
|
||||
event.waitUntil(cacheAdditionalProcessors(versionedCache, BUILD_ASSETS));
|
||||
event.waitUntil(cacheAdditionalProcessors(versionedCache, ASSETS));
|
||||
break;
|
||||
case 'skip-waiting':
|
||||
self.skipWaiting();
|
||||
|
||||
Reference in New Issue
Block a user