PageSourceSearch

https://igry.pro/service-worker.js?V1

js igry.pro collected 2026-10-09 21:27:32 UTC 2,731 bytes, 58 lines download raw bytes

1'use strict';
2
3// Меняй версию при обновлении статики вне DLE cache-id (шрифты, иконки)
4var CACHE = 'igrypro-v1';
5
6// ─── Установка ────────────────────────────────────────────────────────────────
7self.addEventListener('install', function(e) {
8  // Активируемся сразу, не ждём закрытия вкладок
9  e.waitUntil(self.skipWaiting());
10});
11
12// ─── Активация ────────────────────────────────────────────────────────────────
13self.addEventListener('activate', function(e) {
14  e.waitUntil(
15    caches.keys().then(function(keys) {
16      // Удаляем все старые кэши с другим именем
17      return Promise.all(
18        keys.filter(function(k) { return k !== CACHE; })
19            .map(function(k) { return caches.delete(k); })
20      );
21    }).then(function() { return self.clients.claim(); })
22  );
23});
24
25// ─── Перехват запросов ─────────────────────────────────────────────────────────
26self.addEventListener('fetch', function(e) {
27  if (e.request.method !== 'GET') return;
28
29  var url = new URL(e.request.url);
30
31  // Только свой origin, не трогаем cross-origin (рекламу, аналитику)
32  if (url.origin !== self.location.origin) return;
33
34  // Cache-first: CSS, JS и шрифты темы
35  // ?v=... в URL гарантирует что новая версия файла = новый URL = новая запись в кэше
36  var isThemeStatic = url.pathname.startsWith('/templates/igroutka_new/css/') ||
37                      url.pathname.startsWith('/templates/igroutka_new/js/') ||
38                      url.pathname.startsWith('/templates/igroutka_new/webfonts/') ||
39                      url.pathname === '/favicon.ico';
40
41  if (isThemeStatic) {
42    e.respondWith(cacheFirst(e.request));
43  }
44  // Всё остальное (HTML, игровые картинки, API) — не трогаем → браузер сам
45});
46
47async function cacheFirst(request) {
48  const cache = await caches.open(CACHE);
49  const cached = await cache.match(request);
50  if (cached) return cached;
51  try {
52    const response = await fetch(request);
53    if (response.ok) cache.put(request, response.clone());
54    return response;
55  } catch {
56    return new Response('', { status: 503 });
57  }
58}

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.