TelegramPWA/src/serviceWorker/assetCache.ts
Alexander Zinchuk 3afcde3217 Initial commit
2021-04-09 14:11:51 +03:00

22 lines
483 B
TypeScript

import { ASSET_CACHE_NAME } from '../config';
declare const self: ServiceWorkerGlobalScope;
export async function respondWithCache(e: FetchEvent) {
const cache = await self.caches.open(ASSET_CACHE_NAME);
const cached = await cache.match(e.request);
if (cached) {
return cached;
}
const remote = await fetch(e.request);
cache.put(e.request, remote.clone());
return remote;
}
export function clearAssetCache() {
return self.caches.delete(ASSET_CACHE_NAME);
}