serviceWorker.js 952 B

1234567891011121314151617181920212223242526272829303132333435
  1. const CHATGPT_NEXT_WEB_CACHE = "chatgpt-next-web-cache";
  2. self.addEventListener('activate', function (event) {
  3. console.log('ServiceWorker activated.');
  4. });
  5. self.addEventListener('install', function (event) {
  6. event.waitUntil(
  7. caches.open(CHATGPT_NEXT_WEB_CACHE)
  8. .then(function (cache) {
  9. return cache.addAll([
  10. '/',
  11. ]);
  12. })
  13. );
  14. });
  15. self.addEventListener('fetch', function (event) {
  16. event.respondWith(
  17. caches.match(event.request)
  18. .then(function (response) {
  19. return response || fetch(event.request);
  20. })
  21. );
  22. });
  23. if ('serviceWorker' in navigator) {
  24. window.addEventListener('load', function () {
  25. navigator.serviceWorker.register('/serviceWorker.js').then(function (registration) {
  26. console.log('ServiceWorker registration successful with scope: ', registration.scope);
  27. }, function (err) {
  28. console.error('ServiceWorker registration failed: ', err);
  29. });
  30. });
  31. }