sw

/** * OFFICIAL SERVICE WORKER LIPUTANSBM.COM * VERSION: 3.0.1 (Real-time Keyword Tracking & Dynamic Indexing) * SIGNATURE: AUTHENTIC_LIPUTANSBM_CODE_SECURE_2026 */ const CACHE_NAME = 'liputansbm-v3-realtime'; const OFFLINE_URL = '/offline.html'; // Opsional: Halaman saat tidak ada sinyal // 1. Install & Cache Dasar self.addEventListener('install', event => { event.waitUntil( caches.open(CACHE_NAME).then(cache => { return cache.addAll(['/', '/offline.html', '/css/style.css']); }) ); self.skipWaiting(); }); // 2. Strategi Fetch: Stale-While-Revalidate (Cocok untuk Berita) self.addEventListener('fetch', event => { if (event.request.mode === 'navigate') { event.respondWith( fetch(event.request).catch(() => caches.match(OFFLINE_URL)) ); return; } event.respondWith( caches.match(event.request).then(response => { const fetchPromise = fetch(event.request).then(networkResponse => { // Update cache otomatis dengan berita terbaru if (networkResponse.ok) { const cacheCopy = networkResponse.clone(); caches.open(CACHE_NAME).then(cache => cache.put(event.request, cacheCopy)); } return networkResponse; }); return response || fetchPromise; }) ); }); // 3. High-Level Keyword & Interest Sync self.addEventListener('message', (event) => { if (event.data && event.data.type === 'KEYWORD_SYNC') { const { payload } = event.data; // Verifikasi Keamanan: Pastikan data hanya dari domain liputansbm.com console.log(`%c [LSB-TRACKING] Memproses Keyword: ${payload.term}`, "color: #00ff00"); // Gunakan Background Sync untuk data persistensi if ('sync' in self.registration) { event.waitUntil( self.registration.sync.register('lsb-sync-interest') ); } // Simulasi pengiriman data ke Big Data Analytics LiputanSBM // fetch('https://api.liputansbm.com/v1/log', { // method: 'POST', // body: JSON.stringify(payload), // headers: { 'Content-Type': 'application/json' } // }).catch(err => console.error("Sync Pending: Disimpan di background.")); } }); 

// Penambahan untuk menyebarkan notifikasi berita otomatis
self.addEventListener('push', function(event) {
  const data = event.data.json(); // Mengambil data berita dari server
  const options = {
    body: data.body,
    icon: '/img/logo-liputan.png',
    badge: '/img/badge.png',
    data: { url: data.url } // Link berita
  };

  event.waitUntil(
    self.registration.showNotification(data.title, options)
  );
});

// Membuka berita saat notifikasi diklik
self.addEventListener('notificationclick', function(event) {
  event.notification.close();
  event.waitUntil(
    clients.openWindow(event.notification.data.url)
  );
});

 /* --- Tanda Tangan Digital Otentik liputansbm.com --- */


Posting Komentar

0 Komentar
Posting Komentar (0)
To Top
// Memaksa semua gambar di postingan menggunakan loading='lazy' document.querySelectorAll('.post-body img').forEach(img => { img.setAttribute('loading', 'lazy'); // Mengubah resolusi gambar Blogger ke format WebP otomatis let src = img.getAttribute('src'); if (src.includes('s1600') || src.includes('s640')) { img.setAttribute('src', src.replace(/\/s(1600|640)\//, '/s1200-rw/')); } }); let timeout = null; window.addEventListener('scroll', () => { clearTimeout(timeout); timeout = setTimeout(() => { // Jalankan tracker hanya setelah user berhenti scroll selama 200ms trackUserInterest(); }, 200); }, {passive: true});