Created
February 17, 2018 00:51
-
-
Save thesparrow/d2253641ec72b0a0618c15ca999d35d0 to your computer and use it in GitHub Desktop.
Revisions
-
thesparrow created this gist
Feb 17, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ //Offline Web Applications course on Udacity : Grow with Google Application Course //code is placed in the controller file - not in the service worker itself IndexController.prototype._registerServiceWorker = function () { if (!navigator.serviceWorker) return; //feature detection var indexController = this; navigator.serviceWorker.register('/sw.js').then(function (reg) { //if no controller found - latest version is already loaded if (!navigator.serviceWorker.controller) return; // If there's an updated worker already waiting if (reg.waiting) { indexController._updateReady(); return; } // If there's an updated worker installing, track its progress. If it becomes "installed" if (reg.installed) { indexController._updateReady(); return; } //otherwise, listen for new installing workers arriving. // If one arrives, track its progress. reg.addEventListener('updateFound', function () { indexController._trackInstalling(reg.installing); }); }); };