PageSourceSearch

https://vikna.tv/adt-pwa-sw.js

js vikna.tv collected 2026-09-24 21:36:38 UTC 3,988 bytes, 102 lines download raw bytes

1"use strict";
2
3const cacheVersion = '1.2.0';
4const offlinePages = {"ua":"/pwa/offline-ua.html","ru":"/pwa/offline-ru.html"};
5
6importScripts('https://storage.googleapis.com/workbox-cdn/releases/6.4.1/workbox-sw.js');
7importScripts('https://web.webpushs.com/sp-push-worker-fb.js?ver=2.0');
8
9if (workbox) {
10    const isManagedCache = (name) =>
11        /^(?:amp-)?(?:pages|assets|manifest|images|fonts|offline)-/.test(name);
12
13    // Admin-bar assets load for logged-in users only and would eat the assets- entry budget.
14    const isAdminAsset = (url) =>
15        /\/wp-includes\/(?:css|js)\/(?:admin-bar|dashicons|hoverintent)/i.test(url);
16
17    const getOfflinePage = (url) =>
18        offlinePages[url.pathname.split('/')[1]] || offlinePages.ua;
19
20    self.addEventListener('install', event => {
21        event.waitUntil(
22            caches.open(`offline-${cacheVersion}`)
23                .then(cache => cache.addAll(Object.values(offlinePages)))
24                .catch(e => console.error('PWA: offline precache failed', e))
25                .then(() => self.skipWaiting())
26        );
27    });
28
29    self.addEventListener('activate', event => {
30        event.waitUntil(
31            caches.keys().then(cacheNames => Promise.all(
32                cacheNames
33                    .filter(cacheName =>
34                        isManagedCache(cacheName)
35                        && !cacheName.endsWith(`-${cacheVersion}`)
36                    )
37                    .map(cacheName => caches.delete(cacheName))
38            )).then(() => self.clients.claim())
39        );
40    });
41
42    workbox.routing.setCatchHandler(async ({request, url}) => {
43        if (request.mode !== 'navigate') {
44            return Response.error();
45        }
46
47        const offlinePage = getOfflinePage(url);
48        const cached = await caches.match(offlinePage);
49
50        if (!cached) {
51            console.error(`PWA: offline page missing from cache: ${offlinePage}`);
52        }
53
54        return cached || Response.error();
55    });
56
57    // HTML is never cached. The route exists only so a failed navigation reaches the catch
58    // handler above instead of the browser's built-in error page.
59    workbox.routing.registerRoute(
60        ({request}) =>
61            request.mode === 'navigate'
62            && !request.url.match(new RegExp('/wp-(admin|login)|preview|cart|ajax|s=', 'i'))
63            && !request.url.match(new RegExp('\\.xml', 'i')),
64        new workbox.strategies.NetworkOnly()
65    );
66
67    workbox.routing.registerRoute(
68        ({request}) => request.destination === 'image',
69        new workbox.strategies.CacheFirst({
70            cacheName: `images-${cacheVersion}`,
71            plugins: [
72                new workbox.cacheableResponse.CacheableResponsePlugin({statuses: [200]}),
73                new workbox.expiration.ExpirationPlugin({
74                    maxEntries: 150,
75                    maxAgeSeconds: 60 * 60 * 24 * 30, // 30 днів
76                    purgeOnQuotaError: true,
77                }),
78            ],
79        }),
80    );
81
82    // Everything else: css, js, fonts, the adt-pwa REST responses.
83    workbox.routing.registerRoute(
84        ({request, url}) =>
85            url.origin === self.location.origin
86            && !['image', 'document', 'serviceworker'].includes(request.destination)
87            && !isAdminAsset(request.url)
88            && !/\/adt-pwa-sw.*\.js$/.test(url.pathname),
89        new workbox.strategies.NetworkFirst({
90            cacheName: `assets-${cacheVersion}`,
91            networkTimeoutSeconds: 3,
92            plugins: [
93                new workbox.cacheableResponse.CacheableResponsePlugin({statuses: [200]}),
94                new workbox.expiration.ExpirationPlugin({
95                    maxEntries: 120,
96                    maxAgeSeconds: 60 * 60 * 24 * 7, // 7 днів
97                    purgeOnQuotaError: true,
98                }),
99            ],
100        }),
101    );
102}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.