HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1014-azure #14~24.04.1-Ubuntu SMP Fri Oct 3 20:52:11 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/smarthr-co-in/demo/mobile/buyer/pwa/template-rtl/service-worker.js
'use strict';

// Update cache names any time any of the cached files change.
const CACHE_NAME = 'static-cache-v2';
const DATA_CACHE_NAME = 'data-cache-v1';

// Add list of files to cache here.
const FILES_TO_CACHE = [
  '/',
  '/index.html',
  '/add-client.html',
  '/add-department.html',
  '/add-designation.html',
  '/add-employee.html',
  '/add-holiday.html',
  '/add-leave.html',
  '/add-leavetype.html',
  '/add-performance-appraisal.html',
  '/add-performance-indicator.html',
  '/add-project.html',
  '/add-salary.html',
  '/add-tax.html',
  '/add-user.html',
  '/assets.html',
  '/attendance.html',
  '/attendance-list.html',
  '/calendar.html',
  '/calendar-page.html',
  '/change-password.html',
  '/chat.html',
  '/chat-view.html',
  '/clients.html',
  '/company-settings.html',
  '/contacts.html',
  '/create-estimate.html',
  '/create-invoice.html',
  '/departments.html',
  '/designations.html',
  '/edit-assets.html',
  '/edit-attendance.html',
  '/edit-client.html',
  '/edit-department.html',
  '/edit-designation.html',
  '/edit-employee.html',
  '/edit-estimate.html',
  '/edit-holiday.html',
  '/edit-invoice.html',
  '/edit-leavetype.html',
  '/edit-performance-appraisal.html',
  '/edit-performance-indicator.html',
  '/edit-project.html',
  '/edit-salary.html',
  '/edit-tax.html',
  '/edit-user.html',
  '/email.html',
  '/email-list.html',
  '/email-settings.html',
  '/email-view.html',
  '/employees.html',
  '/estimates.html',
  '/estimate-view.html',
  '/forgot-password.html',
  '/holidays.html',
  '/incoming-call.html',
  '/invoices.html',
  '/invoice-settings.html',
  '/invoice-view.html',
  '/leaves.html',
  '/leave-types.html',
  '/leave-view.html',
  '/localization.html',
  '/login.html',
  '/notifications.html',
  '/notifications-settings.html',
  '/payments.html',
  '/performance-appraisal.html',
  '/performance-indicator.html',
  '/policies.html',
  '/profile.html',
  '/projects.html',
  '/project-view.html',
  '/register.html',
  '/salary.html',
  '/salary-settings.html',
  '/salary-view.html',
  '/settings.html',
  '/tasks.html',
  '/task-view.html',
  '/taxes.html',
  '/users.html',
  '/video-call.html',
  '/voice-call.html',
  '/walkthrough.html',
  '/manifest.json',
  '/assets/css/bootstrap.min.css',
  '/assets/css/bootstrap-datetimepicker.min.css',
  '/assets/css/style.css',
  '/assets/plugins/css/all.css',
  '/assets/plugins/css/fontawesome.min.css',
  '/assets/plugins/swiper/swiper-bundle.min.css',
  '/assets/plugins/swiper/swiper-bundle.min.js',
  '/assets/js/jquery-3.7.1.min.js',
  '/assets/js/moment.min.js',
  '/assets/js/bootstrap.bundle.min.js',
  '/assets/js/chart.bundle.js',
  '/assets/js/install.js',
  '/assets/js/script.js',
  '/assets/js/bootstrap-datetimepicker.min.js',
  '/assets/fonts/MaterialIcons-Regular.woff2',
  '/assets/fonts/MaterialIcons-Regular.woff',
  '/assets/plugins/webfonts/fa-solid-900.woff2',
  '/assets/plugins/webfonts/fa-regular-400.woff2',
  '/assets/plugins/webfonts/fa-solid-900.woff',
  '/assets/plugins/webfonts/fa-regular-400.woff',
  '/assets/plugins/webfonts/fa-solid-900.ttf',
  '/assets/plugins/webfonts/fa-regular-400.ttf',
  '/assets/img/logo.png',
  '/assets/img/icons/icon-32x32.png',
  '/assets/img/icons/icon-128x128.png',
  '/assets/img/icons/icon-144x144.png',
  '/assets/img/icons/icon-152x152.png',
  '/assets/img/icons/icon-192x192.png',
  '/assets/img/icons/icon-256x256.png',
  '/assets/img/icons/icon-512x512.png',
  '/assets/img/favicon.png',
  '/assets/img/chat.png',
  '/assets/img/invoice-logo.png',
  '/assets/img/logo2.png',
  '/assets/img/placeholder.jpg',
  '/assets/img/project.png',
  '/assets/img/upload-icon.png',
  '/assets/img/user.jpg',
  '/assets/img/user-02.jpg',
  '/assets/img/user-03.jpg',
  '/assets/img/user-04.jpg',
  '/assets/img/user-05.jpg',
  '/assets/img/user-06.jpg',
  '/assets/img/video-call.jpg',
];

self.addEventListener('install', (evt) => {
  console.log('[ServiceWorker] Install');
  // Precache static resources here.
  evt.waitUntil(
    caches.open(CACHE_NAME).then((cache) => {
      console.log('[ServiceWorker] Pre-caching offline page');
      return cache.addAll(FILES_TO_CACHE);
    })
  );
  self.skipWaiting();
});

self.addEventListener('activate', (evt) => {
  console.log('[ServiceWorker] Activate');
  // Remove previous cached data from disk.
  evt.waitUntil(
    caches.keys().then((keyList) => {
      return Promise.all(keyList.map((key) => {
        if (key !== CACHE_NAME && key !== DATA_CACHE_NAME) {
          console.log('[ServiceWorker] Removing old cache', key);
          return caches.delete(key);
        }
      }));
    })
);
  self.clients.claim();
});

self.addEventListener('fetch', (evt) => {
  console.log('[ServiceWorker] Fetch', evt.request.url);
  // Add fetch event handler here.
  if (evt.request.url.includes('/forecast/')) {
  console.log('[Service Worker] Fetch (data)', evt.request.url);
  evt.respondWith(
      caches.open(DATA_CACHE_NAME).then((cache) => {
        return fetch(evt.request)
            .then((response) => {
              // If the response was good, clone it and store it in the cache.
              if (response.status === 200) {
                cache.put(evt.request.url, response.clone());
              }
              return response;
            }).catch((err) => {
              // Network request failed, try to get it from the cache.
              return cache.match(evt.request);
            });
      }));
  return;
}
evt.respondWith(
    caches.open(CACHE_NAME).then((cache) => {
      return cache.match(evt.request)
          .then((response) => {
            return response || fetch(evt.request);
          });
    })
);
});