Guest User

Untitled

a guest
Feb 18th, 2017
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var serviceWorkerUri = '/sw.js';
  2.  
  3. if ('serviceWorker' in navigator) {
  4.     navigator.serviceWorker.register(serviceWorkerUri).then(function() {
  5.  
  6.         // Registration was successful. Now, check to see whether the service worker is controlling the page.
  7.         if (navigator.serviceWorker.controller) {
  8.  
  9.             console.log('Assets cached by the controlling service worker.');
  10.  
  11.         } else {
  12.  
  13.             console.log('Please reload this page to allow the service worker to handle network operations.');
  14.  
  15.         }
  16.     }).catch(function(error) {
  17.  
  18.         console.log('ERROR: ' + error);
  19.  
  20.     });
  21.  
  22. } else {
  23.  
  24.     // The current browser doesn't support service workers.
  25.     console.log('Service workers are not supported in the current browser.');
  26.  
  27. }
Add Comment
Please, Sign In to add comment