/*
 Copyright 2015 Google Inc. All Rights Reserved.
 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.
*/

'use strict';

// Incrementing CACHE_VERSION will kick off the install event and force previously cached
// resources to be cached again.
const CACHE_VERSION = 1;
let CURRENT_CACHES = {
  offline: 'offline-v' + CACHE_VERSION
};
const OFFLINE_URL = 'offline.html';

function createCacheBustedRequest(url) {
  let request = new Request(url, {cache: 'reload'});
  // See https://fetch.spec.whatwg.org/#concept-request-mode
  // This is not yet supported in Chrome as of M48, so we need to explicitly check to see
  // if the cache: 'reload' option had any effect.
  if ('cache' in request) {
    return request;
  }

  // If {cache: 'reload'} didn't have any effect, append a cache-busting URL parameter instead.
  let bustedUrl = new URL(url, self.location.href);
  bustedUrl.search += (bustedUrl.search ? '&' : '') + 'cachebust=' + Date.now();
  return new Request(bustedUrl);
}

self.addEventListener('install', event => {
  event.waitUntil(
    // We can't use cache.add() here, since we want OFFLINE_URL to be the cache key, but
    // the actual URL we end up requesting might include a cache-busting parameter.
    fetch(createCacheBustedRequest(OFFLINE_URL)).then(function(response) {
      return caches.open(CURRENT_CACHES.offline).then(function(cache) {
        return cache.put(OFFLINE_URL, response);
      });
    })
  );
});

self.addEventListener('activate', event => {
  // Delete all caches that aren't named in CURRENT_CACHES.
  // While there is only one cache in this example, the same logic will handle the case where
  // there are multiple versioned caches.
  let expectedCacheNames = Object.keys(CURRENT_CACHES).map(function(key) {
    return CURRENT_CACHES[key];
  });

  event.waitUntil(
    caches.keys().then(cacheNames => {
      return Promise.all(
        cacheNames.map(cacheName => {
          if (expectedCacheNames.indexOf(cacheName) === -1) {
            // If this cache name isn't present in the array of "expected" cache names,
            // then delete it.
            console.log('Deleting out of date cache:', cacheName);
            return caches.delete(cacheName);
          }
        })
      );
    })
  );
});

self.addEventListener("fetch", function(event){
  // We only want to call event.respondWith() if this is a navigation request
  // for an HTML page.
  // request.mode of 'navigate' is unfortunately not supported in Chrome
  // versions older than 49, so we need to include a less precise fallback,
  // which checks for a GET request with an Accept: text/html header.
  if (event.request.mode === 'navigate' ||
      (event.request.method === 'GET' &&
       event.request.headers.get('accept').includes('text/html'))) {
    console.log('Handling fetch event for', event.request.url);
    event.respondWith(
      fetch(event.request).catch(error => {
        // The catch is only triggered if fetch() throws an exception, which will most likely
        // happen due to the server being unreachable.
        // If fetch() returns a valid HTTP response with an response code in the 4xx or 5xx
        // range, the catch() will NOT be called. If you need custom handling for 4xx or 5xx
        // errors, see https://github.com/GoogleChrome/samples/tree/gh-pages/service-worker/fallback-response
        console.log('Fetch failed; returning offline page instead.', error);
        return caches.match(OFFLINE_URL);
      })
    );
  }

  // If our if() condition is false, then this fetch handler won't intercept the request.
  // If there are any other fetch handlers registered, they will get a chance to call
  // event.respondWith(). If no fetch handlers call event.respondWith(), the request will be
  // handled by the browser as if there were no service worker involvement.
});

@@ -1,4324 +1,592 @@
-/*%0A Copyright 2015 Google Inc. All Rights Reserved.%0A Licensed under the Apache License, Version 2.0 (the %22License%22);%0A you may not use this file except in compliance with the License.%0A You may obtain a copy of the License at%0A http://www.apache.org/licenses/LICENSE-2.0%0A Unless required by applicable law or agreed to in writing, software%0A distributed under the License is distributed on an %22AS IS%22 BASIS,%0A WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A See the License for the specific language governing permissions and%0A limitations under the License.%0A*/%0A%0A'use strict';%0A%0A// Incrementing CACHE_VERSION will kick off the install event and force previously cached%0A// resources to be cached again.%0Aconst CACHE_VERSION = 1;%0Alet CURRENT_CACHES = %7B%0A  offline: 'offline-v' + CACHE_VERSION%0A%7D;%0Aconst OFFLINE_URL = 'offline.html';%0A%0Afunction createCacheBustedRequest(url) %7B%0A  let request = new Request(url, %7Bcache: 'reload'%7D);%0A  // See https://fetch.spec.whatwg.org/#concept-request-mode%0A  // This is not yet supported in Chrome as of M48, so we need to explicitly check to see%0A  // if the cache: 'reload' option had any effect.%0A  if ('cache' in request) %7B%0A    return request;%0A  %7D%0A%0A  // If %7Bcache: 'reload'%7D didn't have any effect, append a cache-busting URL parameter instead.%0A  let bustedUrl = new URL(url, self.location.href);%0A  bustedUrl.search += (bustedUrl.search ? '&' : '') + 'cachebust=' + Date.now();%0A  return new Request(bustedUrl);%0A%7D%0A%0Aself.addEventListener('install', event =%3E %7B%0A  event.waitUntil(%0A    // We can't use cache.add() here, since we want OFFLINE_URL to be the cache key, but%0A    // the actual URL we end up requesting might include a cache-busting parameter.%0A    fetch(createCacheBustedRequest(OFFLINE_URL)).then(function(response) %7B%0A      return caches.open(CURRENT_CACHES.offline).then(function(cache) %7B%0A        return cache.put(OFFLINE_URL, response);%0A      %7D);%0A    %7D)%0A  );%0A%7D);%0A%0Aself.addEventListener('activate', event =%3E %7B%0A  // Delete all caches that aren't named in CURRENT_CACHES.%0A  // While there is only one cache in this example, the same logic will handle the case where%0A  // there are multiple versioned caches.%0A  let expectedCacheNames = Object.keys(CURRENT_CACHES).map(function(key) %7B%0A    return CURRENT_CACHES%5Bkey%5D;%0A  %7D);%0A%0A  event.waitUntil(%0A    caches.keys().then(cacheNames =%3E %7B%0A      return Promise.all(%0A        cacheNames.map(cacheName =%3E %7B%0A          if (expectedCacheNames.indexOf(cacheName) === -1) %7B%0A            // If this cache name isn't present in the array of %22expected%22 cache names,%0A            // then delete it.%0A            console.log('Deleting out of date cache:', cacheName);%0A            return caches.delete(cacheName);%0A          %7D%0A        %7D)%0A      );%0A    %7D)%0A  );%0A%7D);%0A%0Aself.addEventListener(%22fetch%22, function(event)%7B%0A  // We only want to call event.respondWith() if this is a navigation request%0A  // for an HTML page.%0A  // request.mode of 'navigate' is unfortunately not supported in Chrome%0A  // versions older than 49, so we need to include a less precise fallback,%0A  // which checks for a GET request with an Accept: text/html header.%0A  if (event.request.mode === 'navigate' %7C%7C%0A      (event.request.method === 'GET' &&%0A       event.request.headers.get('accept').includes('text/html'))) %7B%0A    console.log('Handling fetch event for', event.request.url);%0A    event.respondWith(%0A      fetch(event.request).catch(error =%3E %7B%0A        // The catch is only triggered if fetch() throws an exception, which will most likely%0A        // happen due to the server being unreachable.%0A        // If fetch() returns a valid HTTP response with an response code in the 4xx or 5xx%0A        // range, the catch() will NOT be called. If you need custom handling for 4xx or 5xx%0A        // errors, see https://github.com/GoogleChrome/samples/tree/gh-pages/service-worker/fallback-response%0A        console.log('Fetch failed; returning offline page instead.', error);%0A        return caches.match(OFFLINE_URL);%0A      %7D)%0A    );%0A  %7D%0A%0A  // If our if() condition is false, then this fetch handler won't intercept the request.%0A  // If there are any other fetch handlers registered, they will get a chance to call%0A  // event.respondWith(). If no fetch handlers call event.respondWith(), the request will be%0A  // handled by the browser as if there were no service worker involvement.
+let version = '0.0.1';%0A%0Aself.addEventListener('install', e =%3E %7B%0A  let timeStamp = Date.now();%0A  e.waitUntil(%0A    caches.open('offline').then(cache =%3E %7B%0A      return cache.addAll(%5B%0A        %60/%60,%0A        %60offline.html?timestamp=$%7BtimeStamp%7D%60%0A      %5D)%0A      .then(() =%3E self.skipWaiting());%0A    %7D)%0A  )%0A%7D);%0A%0Aself.addEventListener('activate',  event =%3E %7B%0A  event.waitUntil(self.clients.claim());%0A%7D);%0A%0Aself.addEventListener('fetch', event =%3E %7B%0A  event.respondWith(%0A    caches.match(event.request, %7BignoreSearch:true%7D).then(response =%3E %7B%0A      return response %7C%7C fetch(event.request);%0A    %7D)%0A  );
 %0A%7D);

Update sw.js