var cacheName = 'fragile-shell-v20160809';

// Cache a very basic selection of resources
self.addEventListener('install', function(event) {
  event.waitUntil(
    caches.open(cacheName).then(function(cache) {
      return cache.addAll([
        '/iframe-shell/',
        '/iframe-shell/index.html',
        '/iframe-shell/offline.html',
        '/iframe-shell/splash.html',
        '/iframe-shell/amp/01.amp.html?embed=1',
        '/iframe-shell/amp/02.amp.html?embed=1',
        '/iframe-shell/img/shell.jpg',
        '/iframe-shell/img/shell02.jpg',
        '/iframe-shell/img/icons/android-icon-96x96.png',
      ]);
    })
  );
});

self.addEventListener('fetch', function(event) {
  var suffixIndex = event.request.url.indexOf('.amp.html');
  var isEmbed = event.request.url.endsWith('?embed=1');

  // If the requested URL contains "amp.html" and is not an embed,
  // i.e. the AMP page has been requested directly
  if (!isEmbed && suffixIndex !== -1) {
    event.respondWith(
      caches.match(new Request('/iframe-shell/index.html')).then(function(response) {
        // Then we need to serve the shell instead
        return response || fetch('/iframe-shell/index.html');
      })
    );
  } else {
    // Otherwise, we have some very simple functionality to check the cache
    // and serve an offline page when not connected.
    event.respondWith(
      caches.match(event.request).then(function(response) {
        return response || fetch(event.request);
      }).catch(function() {
        return caches.match('/iframe-shell/offline.html');
      })
    );
  }
});

@@ -14,14 +14,13 @@
  = '
+i
 fra
-gil
+m
 e-sh
@@ -34,10 +34,10 @@
 1608
-09
+11
 ';%0A%0A
@@ -132,16 +132,38 @@
 vent) %7B%0A
+  self.skipWaiting();%0A
   event.
@@ -648,137 +648,814 @@
 %0A  )
-;%0A%7D);%0A%0Aself.addEventListener('fetch', function(event) %7B%0A  var suffixIndex = event.request.url.indexOf('.amp.html');%0A  var isEmbed
+%0A%7D);%0A%0A// Clean out old caches%0Aself.addEventListener('activate', function(event) %7B%0A  event.waitUntil(%0A    caches.keys().then(function(existingCacheNames) %7B%0A      return Promise.all(%0A        existingCacheNames.map(function(existingCacheName) %7B%0A          if (existingCacheName !== cacheName) %7B%0A            return caches.delete(existingCacheName);%0A          %7D%0A        %7D)%0A      );%0A    %7D).then(function() %7B%0A      return self.clients.claim();%0A    %7D)%0A  );%0A%7D);%0A%0Aself.addEventListener('fetch', function(event) %7B%0A  // If the URL contains %22.amp.html%22 it might be a page we're interested in%0A  var suffixIndex = event.request.url.indexOf('.amp.html');%0A%0A  if (suffixIndex !== -1) %7B%0A    console.log('event.request.url:', event.request.url);%0A    console.log('event.request.mode:', event.request.mode);%0A    var urlComponents
  = e
@@ -1475,31 +1475,22 @@
 url.
-endsW
+spl
 it
-h
 ('?
-embed=1
 ');%0A
-%0A
+  
   //
@@ -1501,32 +1501,25 @@
 the 
-requested URL contains
+path ends with
  %22
+.
 amp.
@@ -1528,56 +1528,127 @@
 ml%22 
-and is not an embed,%0A  // i.e. the AMP page
+it should be one of our AMP pages%0A    var isAmpPage = urlComponents%5B0%5D.endsWith('.amp.html');%0A    // And if it
  has 
+not 
 been
@@ -1662,57 +1662,140 @@
 ted 
-directly%0A  if (!isEmbed && suffixIndex !== -1
+as an embed with the GET parameter%0A    var isNotEmbedded = urlComponents%5B1%5D !== 'embed=1';%0A%0A    if (isAmpPage && isNotEmbedded
 ) %7B%0A
+  
     
@@ -1811,32 +1811,34 @@
 pondWith(%0A      
+ 
+ 
 caches.match(new
@@ -1909,16 +1909,18 @@
         
+  
 // Then 
@@ -1954,32 +1954,34 @@
 instead%0A        
+ 
+ 
 return response 
@@ -2024,26 +2024,36 @@
 ;%0A      
+  
 %7D)%0A    
+ 
+ 
 );%0A
+    %7D%0A
   %7D else

Fix detection of AMP pages and updating of SW