src/service-worker/install.js
/**
 * Registers the Google AMP Cache service worker if the browser supports SWs.
 */
Registers the Google AMP Cache service worker if the browser supports SWs.
Registers the Google AMP Cache service worker if the browser supports SWs .
function installCacheServiceWorker(win) {
  Services.timerFor(win).delay(() => {
    if (!isExperimentOn(win, TAG)) {
      return;
    }
    if (!('serviceWorker' in navigator)) {
      return;
    }
    if (!getMode().localDev &&
        win.location.hostname !== parseUrl(urls.cdn).hostname) {
      return;
    }
    const kill = isExperimentOn(win, `${TAG}-kill`);
    const entryPoint = `sw${kill ? '-kill' : ''}`;
    const url = calculateEntryPointScriptUrl(location, entryPoint,
        getMode().localDev);
    navigator.serviceWorker.register(url).then(reg => {
      dev().info(TAG, 'ServiceWorker registration successful: ', reg);
    }, err => {
      dev().error(TAG, 'ServiceWorker registration failed: ', err);
    });
  });
}
function installCacheServiceWorker ( win ) { Services . timerFor ( win ) . delay ( ( ) => { if ( ! isExperimentOn ( win , TAG ) ) { return ; } if ( ! ( 'serviceWorker' in navigator ) ) { return ; } if ( ! getMode ( ) . localDev && win . location . hostname !== parseUrl ( urls . cdn ) . hostname ) { return ; } const kill = isExperimentOn ( win , ` ${ TAG } ` ) ; const entryPoint = ` ${ kill ? '-kill' : '' } ` ; const url = calculateEntryPointScriptUrl ( location , entryPoint , getMode ( ) . localDev ) ; navigator . serviceWorker . register ( url ) . then ( reg => { dev ( ) . info ( TAG , 'ServiceWorker registration successful: ' , reg ) ; } , err => { dev ( ) . error ( TAG , 'ServiceWorker registration failed: ' , err ) ; } ) ; } ) ; }
Registers the Google AMP Cache service worker if the browser supports SWs.
Registers the Google AMP Cache service worker if the browser supports SWs .
// The kill experiment is really just a configuration that allows us to // quickly kill the cache service worker without cutting a new version.