diff options
Diffstat (limited to 'docs/_book/service-worker.js')
-rw-r--r-- | docs/_book/service-worker.js | 268 |
1 files changed, 0 insertions, 268 deletions
diff --git a/docs/_book/service-worker.js b/docs/_book/service-worker.js deleted file mode 100644 index 3e9cfea..0000000 --- a/docs/_book/service-worker.js +++ /dev/null @@ -1,268 +0,0 @@ -/** - * Copyright 2016 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. -*/ - -// DO NOT EDIT THIS GENERATED OUTPUT DIRECTLY! -// This file should be overwritten as part of your build process. -// If you need to extend the behavior of the generated service worker, the best approach is to write -// additional code and include it using the importScripts option: -// https://github.com/GoogleChrome/sw-precache#importscripts-arraystring -// -// Alternatively, it's possible to make changes to the underlying template file and then use that as the -// new base for generating output, via the templateFilePath option: -// https://github.com/GoogleChrome/sw-precache#templatefilepath-string -// -// If you go that route, make sure that whenever you update your sw-precache dependency, you reconcile any -// changes made to this original template file with your modified copy. - -// This generated service worker JavaScript will precache your site's resources. -// The code needs to be saved in a .js file at the top-level of your site, and registered -// from your pages in order to be used. See -// https://github.com/googlechrome/sw-precache/blob/master/demo/app/js/service-worker-registration.js -// for an example of how you can register this script and handle various service worker events. - -/* eslint-env worker, serviceworker */ -/* eslint-disable indent, no-unused-vars, no-multiple-empty-lines, max-nested-callbacks, space-before-function-paren, quotes, comma-spacing */ -'use strict'; - -var precacheConfig = [["/Contributing/Modules/CompileAndRun.html","77703217167b1b5370cd222741330fd3"],["/Scripting/SupportLib/index.html","a20303652ec23fea83ae137779201ed6"],["/Usage/CLI.html","f8bb4ad1a3c62d103fea3e9e84112fe1"],["/Usage/Configuration.html","6b2e923bb53c8de168506505d3c58f1c"],["/Usage/Install.html","77cfe2a15a8e0992841a77398e38d34d"],["/Usage/index.html","1098bb18c93de031b96253bdd04658eb"],["/gitbook/fonts/fontawesome/fontawesome-webfont.eot","25a32416abee198dd821b0b17a198a8f"],["/gitbook/fonts/fontawesome/fontawesome-webfont.svg","d7c639084f684d66a1bc66855d193ed8"],["/gitbook/fonts/fontawesome/fontawesome-webfont.ttf","1dc35d25e61d819a9c357074014867ab"],["/gitbook/fonts/fontawesome/fontawesome-webfont.woff","c8ddf1e5e5bf3682bc7bebf30f394148"],["/gitbook/gitbook-plugin-api/api.css","ad443308d0937629d2811cff9053e0c2"],["/gitbook/gitbook-plugin-api/api.js","b592adcca0c3d691f3a351b05e62c77a"],["/gitbook/gitbook-plugin-code/plugin.css","81aeb06c3e8d1c221773e63fe05f737a"],["/gitbook/gitbook-plugin-code/plugin.js","2a3bab062a1c3446333f10c60e8643a1"],["/gitbook/gitbook-plugin-comment/plugin.css","5291855572a41c85319d21a4b45f2eee"],["/gitbook/gitbook-plugin-comment/plugin.js","dc48b2f0bd1e4bdd1ad03d60d32c9bd6"],["/gitbook/gitbook-plugin-emphasize/plugin.css","6c90145b226c807ebbb334bb7d94d8ee"],["/gitbook/gitbook-plugin-fontsettings/fontsettings.js","fab8f6412ce18bb367635b1bcae503ca"],["/gitbook/gitbook-plugin-fontsettings/website.css","056a6db3eef3553a78f3b7e02356b2e7"],["/gitbook/gitbook-plugin-github/plugin.js","93ff35be0de181d440c84e8f6d76ab45"],["/gitbook/gitbook-plugin-highlight/ebook.css","fa203ae16ad9f01f4d20061fb9e7a6cc"],["/gitbook/gitbook-plugin-highlight/website.css","acce01e3e11cbd4b3882e7732d81f954"],["/gitbook/gitbook-plugin-hints/plugin-hints.css","35cad665bf4ba951a2f3a1d3253b6089"],["/gitbook/gitbook-plugin-livereload/plugin.js","9e48eceeaa9ee3f1f734eddd3dfe04da"],["/gitbook/gitbook-plugin-lunr/lunr.min.js","9424f087f85dc7be8f7c7bc35b720f26"],["/gitbook/gitbook-plugin-lunr/search-lunr.js","4e91f557c3d72be045b9e146c2bc90bc"],["/gitbook/gitbook-plugin-offline/service-worker-registration.js","0b4c35226075896152de214f8860b76e"],["/gitbook/gitbook-plugin-pretty-term/terminal.css","02c933b557fe724dcadd3dfa43dfc33c"],["/gitbook/gitbook-plugin-pretty-term/terminal.js","424e08c8a0b2f3d9e6706f15af29a714"],["/gitbook/gitbook-plugin-search/lunr.min.js","9424f087f85dc7be8f7c7bc35b720f26"],["/gitbook/gitbook-plugin-search/search-engine.js","59ed9456a958a2930326955747048f8a"],["/gitbook/gitbook-plugin-search/search.css","6c8330e8aadd979bb37f872182257bdd"],["/gitbook/gitbook-plugin-search/search.js","5ba7dbf7c0e78b02dc48f83d55729e36"],["/gitbook/gitbook-plugin-sharing/buttons.js","e7c1c051d685b9e7530c1a6675e6b119"],["/gitbook/gitbook.js","e53bf9037b1d1c9810486ef4c5493624"],["/gitbook/images/apple-touch-icon-precomposed-152.png","59313d171157503f5de7fd7e07f3c495"],["/gitbook/style.css","88a3a50e3559bc577c1be0de4fcc6c6d"],["/gitbook/theme.js","176e71ac3bf185b7f08e0f6cb919f1e8"],["/index.html","ab2e608a2271cd696e6d299e35137ff5"]]; -var cacheName = 'sw-precache-v3--' + (self.registration ? self.registration.scope : ''); - - -var ignoreUrlParametersMatching = [/^utm_/]; - - - -var addDirectoryIndex = function (originalUrl, index) { - var url = new URL(originalUrl); - if (url.pathname.slice(-1) === '/') { - url.pathname += index; - } - return url.toString(); - }; - -var cleanResponse = function (originalResponse) { - // If this is not a redirected response, then we don't have to do anything. - if (!originalResponse.redirected) { - return Promise.resolve(originalResponse); - } - - // Firefox 50 and below doesn't support the Response.body stream, so we may - // need to read the entire body to memory as a Blob. - var bodyPromise = 'body' in originalResponse ? - Promise.resolve(originalResponse.body) : - originalResponse.blob(); - - return bodyPromise.then(function(body) { - // new Response() is happy when passed either a stream or a Blob. - return new Response(body, { - headers: originalResponse.headers, - status: originalResponse.status, - statusText: originalResponse.statusText - }); - }); - }; - -var createCacheKey = function (originalUrl, paramName, paramValue, - dontCacheBustUrlsMatching) { - // Create a new URL object to avoid modifying originalUrl. - var url = new URL(originalUrl); - - // If dontCacheBustUrlsMatching is not set, or if we don't have a match, - // then add in the extra cache-busting URL parameter. - if (!dontCacheBustUrlsMatching || - !(url.pathname.match(dontCacheBustUrlsMatching))) { - url.search += (url.search ? '&' : '') + - encodeURIComponent(paramName) + '=' + encodeURIComponent(paramValue); - } - - return url.toString(); - }; - -var isPathWhitelisted = function (whitelist, absoluteUrlString) { - // If the whitelist is empty, then consider all URLs to be whitelisted. - if (whitelist.length === 0) { - return true; - } - - // Otherwise compare each path regex to the path of the URL passed in. - var path = (new URL(absoluteUrlString)).pathname; - return whitelist.some(function(whitelistedPathRegex) { - return path.match(whitelistedPathRegex); - }); - }; - -var stripIgnoredUrlParameters = function (originalUrl, - ignoreUrlParametersMatching) { - var url = new URL(originalUrl); - // Remove the hash; see https://github.com/GoogleChrome/sw-precache/issues/290 - url.hash = ''; - - url.search = url.search.slice(1) // Exclude initial '?' - .split('&') // Split into an array of 'key=value' strings - .map(function(kv) { - return kv.split('='); // Split each 'key=value' string into a [key, value] array - }) - .filter(function(kv) { - return ignoreUrlParametersMatching.every(function(ignoredRegex) { - return !ignoredRegex.test(kv[0]); // Return true iff the key doesn't match any of the regexes. - }); - }) - .map(function(kv) { - return kv.join('='); // Join each [key, value] array into a 'key=value' string - }) - .join('&'); // Join the array of 'key=value' strings into a string with '&' in between each - - return url.toString(); - }; - - -var hashParamName = '_sw-precache'; -var urlsToCacheKeys = new Map( - precacheConfig.map(function(item) { - var relativeUrl = item[0]; - var hash = item[1]; - var absoluteUrl = new URL(relativeUrl, self.location); - var cacheKey = createCacheKey(absoluteUrl, hashParamName, hash, false); - return [absoluteUrl.toString(), cacheKey]; - }) -); - -function setOfCachedUrls(cache) { - return cache.keys().then(function(requests) { - return requests.map(function(request) { - return request.url; - }); - }).then(function(urls) { - return new Set(urls); - }); -} - -self.addEventListener('install', function(event) { - event.waitUntil( - caches.open(cacheName).then(function(cache) { - return setOfCachedUrls(cache).then(function(cachedUrls) { - return Promise.all( - Array.from(urlsToCacheKeys.values()).map(function(cacheKey) { - // If we don't have a key matching url in the cache already, add it. - if (!cachedUrls.has(cacheKey)) { - var request = new Request(cacheKey, {credentials: 'same-origin'}); - return fetch(request).then(function(response) { - // Bail out of installation unless we get back a 200 OK for - // every request. - if (!response.ok) { - throw new Error('Request for ' + cacheKey + ' returned a ' + - 'response with status ' + response.status); - } - - return cleanResponse(response).then(function(responseToCache) { - return cache.put(cacheKey, responseToCache); - }); - }); - } - }) - ); - }); - }).then(function() { - - // Force the SW to transition from installing -> active state - return self.skipWaiting(); - - }) - ); -}); - -self.addEventListener('activate', function(event) { - var setOfExpectedUrls = new Set(urlsToCacheKeys.values()); - - event.waitUntil( - caches.open(cacheName).then(function(cache) { - return cache.keys().then(function(existingRequests) { - return Promise.all( - existingRequests.map(function(existingRequest) { - if (!setOfExpectedUrls.has(existingRequest.url)) { - return cache.delete(existingRequest); - } - }) - ); - }); - }).then(function() { - - return self.clients.claim(); - - }) - ); -}); - - -self.addEventListener('fetch', function(event) { - if (event.request.method === 'GET') { - // Should we call event.respondWith() inside this fetch event handler? - // This needs to be determined synchronously, which will give other fetch - // handlers a chance to handle the request if need be. - var shouldRespond; - - // First, remove all the ignored parameters and hash fragment, and see if we - // have that URL in our cache. If so, great! shouldRespond will be true. - var url = stripIgnoredUrlParameters(event.request.url, ignoreUrlParametersMatching); - shouldRespond = urlsToCacheKeys.has(url); - - // If shouldRespond is false, check again, this time with 'index.html' - // (or whatever the directoryIndex option is set to) at the end. - var directoryIndex = 'index.html'; - if (!shouldRespond && directoryIndex) { - url = addDirectoryIndex(url, directoryIndex); - shouldRespond = urlsToCacheKeys.has(url); - } - - // If shouldRespond is still false, check to see if this is a navigation - // request, and if so, whether the URL matches navigateFallbackWhitelist. - var navigateFallback = ''; - if (!shouldRespond && - navigateFallback && - (event.request.mode === 'navigate') && - isPathWhitelisted([], event.request.url)) { - url = new URL(navigateFallback, self.location).toString(); - shouldRespond = urlsToCacheKeys.has(url); - } - - // If shouldRespond was set to true at any point, then call - // event.respondWith(), using the appropriate cache key. - if (shouldRespond) { - event.respondWith( - caches.open(cacheName).then(function(cache) { - return cache.match(urlsToCacheKeys.get(url)).then(function(response) { - if (response) { - return response; - } - throw Error('The cached response that was expected is missing.'); - }); - }).catch(function(e) { - // Fall back to just fetch()ing the request if some unexpected error - // prevented the cached response from being valid. - console.warn('Couldn\'t serve response for "%s" from cache: %O', event.request.url, e); - return fetch(event.request); - }) - ); - } - } -}); - - - - - - - |