gtag, adsense, caching

This commit is contained in:
first@lynx.com
2026-07-23 18:43:16 -04:00
parent ddab5ca728
commit b1a1403c13
13 changed files with 436 additions and 237 deletions

36
sw.js
View File

@ -8,6 +8,12 @@ let localStorageData = {
};
// yandere sim big files, cuphead, ddlc assets, renpy, renpy, buckshot roulette, half life, undertale & deltarune, hollow knight
let cacheable_files = ["YandereSim.data", "cuphead/Build/Build.data.unityweb.", "/ddlc/game/", "/ddlcplus/game/", "/co09/game/", "/co09flipside/game/", "/co09reup/game/", "renpy.data", "game.zip", "buckshot-roulette.pck", "halva_en-", "game.unx", "bog.data", "FTFHAPort.data.unityweb", "Content.tar.part", "thats-not-my-neighbor.pck", ".unityweb", "index.data.path"];
let no_long_cache_dirs = ["deltarune"];
function isNoLongCachePath(pathname) {
return no_long_cache_dirs.some(dir => pathname.includes(`/${dir}/`));
}
self.addEventListener("message", e => {
if (e.data && e.data.type == "localStorage") {
localStorageData = e.data;
@ -17,6 +23,36 @@ self.addEventListener("message", e => {
if (workbox) {
self.skipWaiting();
workbox.core.clientsClaim();
self.addEventListener("activate", event => {
event.waitUntil(
caches.open('resources-cache').then(cache =>
cache.keys().then(requests =>
Promise.all(
requests
.filter(req => isNoLongCachePath(new URL(req.url).pathname))
.map(req => cache.delete(req))
)
)
)
);
});
workbox.routing.registerRoute(
({ url }) => {
if (!url.pathname.includes("/resources/")) return false;
return isNoLongCachePath(url.pathname);
},
new workbox.strategies.NetworkFirst({
cacheName: 'resources-cache-nocache-exceptions',
networkTimeoutSeconds: 10,
plugins: [
new workbox.expiration.ExpirationPlugin({
maxEntries: 300,
maxAgeSeconds: 60 * 60,
}),
],
})
);
workbox.routing.registerRoute(
({ url }) => {