Timers and other features for Heroes of the Storm
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

service-worker-prod.js 2.3 KiB

hace 4 años
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. (function() {
  2. 'use strict';
  3. // Check to make sure service workers are supported in the current browser,
  4. // and that the current page is accessed from a secure origin. Using a
  5. // service worker from an insecure origin will trigger JS console errors.
  6. var isLocalhost = Boolean(window.location.hostname === 'localhost' ||
  7. // [::1] is the IPv6 localhost address.
  8. window.location.hostname === '[::1]' ||
  9. // 127.0.0.1/8 is considered localhost for IPv4.
  10. window.location.hostname.match(
  11. /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
  12. )
  13. );
  14. window.addEventListener('load', function() {
  15. if ('serviceWorker' in navigator &&
  16. (window.location.protocol === 'https:' || isLocalhost)) {
  17. navigator.serviceWorker.register('service-worker.js')
  18. .then(function(registration) {
  19. // updatefound is fired if service-worker.js changes.
  20. registration.onupdatefound = function() {
  21. // updatefound is also fired the very first time the SW is installed,
  22. // and there's no need to prompt for a reload at that point.
  23. // So check here to see if the page is already controlled,
  24. // i.e. whether there's an existing service worker.
  25. if (navigator.serviceWorker.controller) {
  26. // The updatefound event implies that registration.installing is set
  27. var installingWorker = registration.installing;
  28. installingWorker.onstatechange = function() {
  29. switch (installingWorker.state) {
  30. case 'installed':
  31. // At this point, the old content will have been purged and the
  32. // fresh content will have been added to the cache.
  33. // It's the perfect time to display a "New content is
  34. // available; please refresh." message in the page's interface.
  35. break;
  36. case 'redundant':
  37. throw new Error('The installing ' +
  38. 'service worker became redundant.');
  39. default:
  40. // Ignore
  41. }
  42. };
  43. }
  44. };
  45. }).catch(function(e) {
  46. console.error('Error during service worker registration:', e);
  47. });
  48. }
  49. });
  50. })();