forked from rweekly/rweekly.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
qinwf
committed
Nov 16, 2016
1 parent
29c65d7
commit fba8b98
Showing
5 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
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. | ||
*/ | ||
(function() { | ||
'use strict'; | ||
var workerScript = document.currentScript && document.currentScript.dataset.serviceWorker; | ||
|
||
if (workerScript && 'serviceWorker' in navigator) { | ||
navigator.serviceWorker.register(workerScript); | ||
} | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
(global => { | ||
'use strict'; | ||
|
||
// Load the sw-tookbox library. | ||
importScripts('/bower_components/sw-toolbox/sw-toolbox.js'); | ||
|
||
// Turn on debug logging, visible in the Developer Tools' console. | ||
global.toolbox.options.debug = true; | ||
|
||
// Set up a handler for HTTP GET requests: | ||
// - /\.ytimg\.com\// will match any requests whose URL contains 'ytimg.com'. | ||
// A narrower RegExp could be used, but just checking for ytimg.com anywhere | ||
// in the URL should be fine for this sample. | ||
// - toolbox.cacheFirst let us to use the predefined cache strategy for those | ||
// requests. | ||
// global.toolbox.router.get(/\.(cloudflare)|(googleapis)\.com\//, global.toolbox.cacheFirst, { | ||
// // Use a dedicated cache for the responses, separate from the default cache. | ||
// cache: { | ||
// name: 'cdnjs', | ||
// // Expire any entries that are older than 30 seconds. | ||
// maxAgeSeconds: 60 * 60 * 100 | ||
// } | ||
// }); | ||
|
||
global.toolbox.precache(['/index.html', '/random.html', '/about.html',"/","/page2","/page2/index.html","/archive.html"]); | ||
// global.toolbox.options.cache.maxAgeSeconds = 60 * 15; | ||
|
||
// Request the resource from both the cache and the network in parallel. | ||
// Respond with whichever returns first. Usually this will be the cached | ||
// version, if there is one. On the one hand this strategy will always make a | ||
// network request, even if the resource is cached. On the other hand, | ||
// if/when the network request completes the cache is updated, so that future | ||
// cache reads will be more up-to-date. | ||
global.toolbox.router.default = global.toolbox.fastest; | ||
|
||
// Boilerplate to ensure our service worker takes control of the page as soon | ||
// as possible. | ||
global.addEventListener('install', | ||
event => event.waitUntil(global.skipWaiting())); | ||
global.addEventListener('activate', | ||
event => event.waitUntil(global.clients.claim())); | ||
})(self); |