Skip to content

Instantly share code, notes, and snippets.

<html>
<head>
<title>Test</title>
</head>
<body>
<p>
This page will make a CORS-enabled request for <code>https://cors-test.appspot.com/test</code> with an
Authentication header set after the service worker takes control.
</p>
@jeffposnick
jeffposnick / index.html
Created December 9, 2015 21:59
IDB test
<html>
<body>
<script src="https://cdn.rawgit.com/jakearchibald/indexeddb-promised/dd48c031e7f93d6695e89bb504cbe586dfacc073/lib/idb.js"></script>
<script>
idb.open('test', 1).then(db => {
db.transaction('key-val').objectStore('key-val').put('hello', 'world');
});
</script>
</body>
</html>
<html>
<body>
<video controls src="https://cdn.rawgit.com/dominikhlbg/vp8-webm-javascript-decoder/master/webm/The_Google_Story.webm"></video>
<script>
navigator.serviceWorker.register('sw.js');
</script>
</body>
</html>
@jeffposnick
jeffposnick / index.html
Created January 14, 2016 15:26
Possible Firefox Beta bug?
<html>
<head>
<title>Test</title>
</head>
<body>
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js');
navigator.serviceWorker.ready.then(() => {
@jeffposnick
jeffposnick / another.html
Created January 20, 2016 18:16
Offline page test
<html>
<head>
<title>Another Page</title>
</head>
<body>
<p>This is another page.</p>
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js');
}
@jeffposnick
jeffposnick / one.html
Last active March 13, 2016 21:24
Test of client id persistence across navigations
<html>
<head>
<title>One</title>
</head>
<body>
<a href="two.html">Two</a>
<script>
navigator.serviceWorker.register('sw.js');
</script>
</body>
<html>
<head>
<title>Cross Origin Test</title>
</head>
<body>
<script>
navigator.serviceWorker.register('sw.js');
</script>
</body>
</html>
@jeffposnick
jeffposnick / index.html
Created April 8, 2016 16:56
IndexedDB test
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>IndexedDB Test</title>
</head>
<body>
<script>
var indexedDBOpenRequest = indexedDB.open('test', 1);
@jeffposnick
jeffposnick / offline-analytics.js
Created April 22, 2016 14:57
Standalone offline analytics code
/*
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
@jeffposnick
jeffposnick / index.js
Created May 5, 2016 21:11
Given a list of URLs, check to see whether each of them are already stored in a cache
const CACHE_NAME = 'my-cache'; // Or whatever your cache is.
let urls = []; // An array of full, absolute URLs that may or may not be cached.
caches.open(CACHE_NAME)
.then(cache => cache.keys())
.then(responses => responses.map(response => response.url))
.then(urlsInCache => Promise.all(urls.map(url => {
return {
url: url,
cached: urlsInCache.includes(url)