dnk

Форк
0
/
service-worker-prod.js 
55 строк · 2.3 Кб
1
(function() {
2
  'use strict';
3

4
  // Check to make sure service workers are supported in the current browser,
5
  // and that the current page is accessed from a secure origin. Using a
6
  // service worker from an insecure origin will trigger JS console errors.
7
  var isLocalhost = Boolean(window.location.hostname === 'localhost' ||
8
      // [::1] is the IPv6 localhost address.
9
      window.location.hostname === '[::1]' ||
10
      // 127.0.0.1/8 is considered localhost for IPv4.
11
      window.location.hostname.match(
12
        /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
13
      )
14
    );
15

16
  window.addEventListener('load', function() {
17
      if ('serviceWorker' in navigator &&
18
          (window.location.protocol === 'https:' || isLocalhost)) {
19
        navigator.serviceWorker.register('service-worker.js')
20
        .then(function(registration) {
21
          // updatefound is fired if service-worker.js changes.
22
          registration.onupdatefound = function() {
23
            // updatefound is also fired the very first time the SW is installed,
24
            // and there's no need to prompt for a reload at that point.
25
            // So check here to see if the page is already controlled,
26
            // i.e. whether there's an existing service worker.
27
            if (navigator.serviceWorker.controller) {
28
              // The updatefound event implies that registration.installing is set
29
              var installingWorker = registration.installing;
30

31
              installingWorker.onstatechange = function() {
32
                switch (installingWorker.state) {
33
                  case 'installed':
34
                    // At this point, the old content will have been purged and the
35
                    // fresh content will have been added to the cache.
36
                    // It's the perfect time to display a "New content is
37
                    // available; please refresh." message in the page's interface.
38
                    break;
39

40
                  case 'redundant':
41
                    throw new Error('The installing ' +
42
                                    'service worker became redundant.');
43

44
                  default:
45
                    // Ignore
46
                }
47
              };
48
            }
49
          };
50
        }).catch(function(e) {
51
          console.error('Error during service worker registration:', e);
52
        });
53
      }
54
  });
55
})();
56

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.