/*
Copyright 2016 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

(function() {
  'use strict';

  var filesToCache = [
    '.',
    'offline.html'
  ];

  var staticCacheName = 'pages-cache-v2';

  self.addEventListener('install', function(event) {
    console.log('Attempting to install service worker and cache static assets');
    event.waitUntil(
      caches.open(staticCacheName)
      .then(function(cache) {
        return cache.addAll(filesToCache);
      })
    );
  });

  self.addEventListener('fetch', function(event) {
    console.log('Fetch event for ', event.request.url);
    event.respondWith(
      caches.match(event.request).then(function(response) {
        if (response) {
          console.log('Found ', event.request.url, ' in cache');
          return response;
        }
        console.log('Network request for ', event.request.url);
        return fetch(event.request).then(function(response) {
          if (response.status === 404) {
            return caches.match('pages/404.html');
          }
          return caches.open(staticCacheName).then(function(cache) {
            if (event.request.url.indexOf('test') < 0) {
              cache.put(event.request.url, response.clone());
            }
            return response;
          });
        });
      }).catch(function(error) {
        console.log('Error, ', error);
        return caches.match('pages/offline.html');
      })
    );
  });

  self.addEventListener('activate', function(event) {
    console.log('Activating new service worker...');

    var cacheWhitelist = [staticCacheName];

    event.waitUntil(
      caches.keys().then(function(cacheNames) {
        return Promise.all(
          cacheNames.map(function(cacheName) {
            if (cacheWhitelist.indexOf(cacheName) === -1) {
              return caches.delete(cacheName);
            }
          })
        );
      })
    );
  });

})();

@@ -999,32 +999,33 @@
 fetch', function
+ 
 (event) %7B%0A    co
@@ -1026,897 +1026,149 @@
     
-console.log('Fetch event for ', event.request.url);%0A    event.respondWith(%0A      caches.match(event.request).then(function(response) %7B%0A        if (response) %7B%0A          console.log('Found ', event.request.url, ' in cache');%0A          return response;%0A        %7D%0A        console.log('Network request for ', event.request.url);%0A        return fetch(event.request).then(function(response) %7B%0A          if (response.status === 404) %7B%0A            return caches.match('pages/404.html');%0A          %7D%0A          return caches.open(staticCacheName).then(function(cache) %7B%0A            if (event.request.url.indexOf('test') %3C 0) %7B%0A              cache.put(event.request.url, response.clone());%0A            %7D%0A            return response;%0A          %7D);%0A        %7D);%0A      %7D).catch(function(error) %7B%0A        console.log('Error, ', error);%0A        return caches.match('pages/offline.html');%0A      %7D)%0A    );%0A  
+var response = new Response('%3Ch1%3ESei offline!%3C/h1%3E',%0A        %7B headers: %7B 'Content-Type': 'text/html' %7D %7D);%0A    event.respondWith(response);%0A
 %7D);%0A

Update sw.js