nathamanath
This looks great. However I cannot work out how to get GLTFLoader to load glb from the cache!
in service worker
self.addEventListener("fetch", (event) => {
if (event.request.method !== "GET") return;
event.respondWith(
(async () => {
const url = event.request.url;
const isGlb = url.endsWith(".glb");
if (isGlb) {
// Try to get the response from a cache.
const cache = await caches.open(CACHE_NAME);
const cachedResponse = await cache.match(event.request);
if (cachedResponse) {
// If we found a match in the cache, return it, but also
// update the entry in the cache in the background.
event.waitUntil(cache.add(event.request));
return cachedResponse;
}
}
// If we didn't find a match in the cache, use the network.
const res = await fetch(event.request).catch(() =>
caches.match(event.request).then((res) => res)
);
if (isGlb) {
const copyCache = res.clone();
caches.open(CACHE_NAME).then((cache) => {
cache.put(event.request, copyCache);
});
}
return res;
})()
);
});