PageSourceSearch

https://www.babnet.net/assets/sw-cache-v4.js

js babnet.net collected 2026-10-02 04:25:27 UTC 3,735 bytes, 111 lines download raw bytes

1// /assets/sw-cache-v3.js (version PATCHÉE compatible Project Agora / GPT)
2// Backup your original file first: /assets/sw-cache-v3.js.bak
3
4const CACHE_NAME = 'babnet-assets-v10122025';
5
6const FILES_TO_CACHE = [
7  // CSS
8  '/assets/css/bootstrap.min.css',
9  '/assets/css/animate.min.css',
10  '/assets/css/style.min.css',
11  '/assets/css/babnet_v52.min.css',
12  '/assets/css/responsive_v10.min.css',
13  '/assets/css/print.min-2022-v6.css',
14  '/assets/css/homepagecss-2026-v1.css',
15
16  // Fonts
17  'https://fonts.gstatic.com/s/amiri/v14/J7aRnpd8CGxBHpUrtLMA7w.woff2',
18  'https://fonts.gstatic.com/s/opensans/v17/mem5YaGs126MiZpBA-UN7rgOUuhp.woff2',
19
20  // Logos / Images
21  '/assets/images/logo-babnetx24.webp',
22  '/assets/images/favicon.ico',
23
24  // JS
25  '/assets/js/allinone-2024.js'
26];
27
28self.addEventListener('install', (event) => {
29  console.log('? SW install event');
30  event.waitUntil(
31    caches.open(CACHE_NAME).then((cache) => {
32      console.log('? SW opened cache, adding files...');
33      return cache.addAll(FILES_TO_CACHE);
34    }).catch((err) => {
35      console.error('? SW cache.addAll error:', err);
36    })
37  );
38  self.skipWaiting();
39});
40
41self.addEventListener('activate', (event) => {
42  event.waitUntil(
43    caches.keys().then((keys) =>
44      Promise.all(
45        keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key))
46      )
47    )
48  );
49  self.clients.claim(); // Take control immediately after activation
50});
51
52// ----------------- PATCHED fetch handler (INSÉRER ICI) -----------------
53// Liste des domaines / patterns à ne jamais intercepter (header-bidding / GPT / Ads)
54const SW_BYPASS = [
55  'pabidding.io',
56  'pwl.io',
57  'cdn.pabidding.io',
58  'g.doubleclick.net',
59  'doubleclick.net',
60  'googlesyndication.com',
61  'googletagservices.com',
62  'googletagmanager.com',
63  'pagead2.googlesyndication.com',
64  'securepubads.g.doubleclick.net',
65  'adservice.google.com'
66];
67
68self.addEventListener('fetch', (event) => {
69  const url = event.request && event.request.url ? event.request.url : '';
70
71  // 1) Si l'URL correspond à un domaine critique (ads / header-bidding / gpt), NE PAS INTERCEPTER
72  for (const domain of SW_BYPASS) {
73    if (url.includes(domain)) {
74      // On ne répond pas ici : laisser la requête passer au réseau normalement
75      return;
76    }
77  }
78
79  // 2) Comportement cache-first sécurisé pour assets locaux uniquement
80  event.respondWith((async () => {
81    try {
82      const cached = await caches.match(event.request);
83      if (cached) return cached;
84
85      const networkResponse = await fetch(event.request);
86
87      // Cache uniquement les assets statiques same-origin et types sûrs
88      if (event.request.url.startsWith(self.location.origin)) {
89        const contentType = networkResponse.headers.get('content-type') || '';
90        const isStatic = /(css|javascript|image|font|svg|webp|woff2)/i.test(contentType);
91        if (networkResponse && networkResponse.ok && isStatic) {
92          const cache = await caches.open(CACHE_NAME);
93          // Some requests are opaque or problematic to cache - use try/catch to be safe
94          try {
95            cache.put(event.request, networkResponse.clone());
96          } catch (e) {
97            // ignore cache put errors for problematic requests
98            console.warn('SW: cache.put failed for', event.request.url, e);
99          }
100        }
101      }
102
103      return networkResponse;
104    } catch (err) {
105      // fallback : return a network error response (could return an offline page if you have one)
106      return Response.error();
107    }
108  })());
109});
110// ----------------------------------------------------------------------
111

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.