Skip to content

Commit dd8e221

Browse files
committed
Added service worker 😳
1 parent f04ec77 commit dd8e221

18 files changed

+221
-2
lines changed

bigimage/bigImage1000.png

472 KB
Loading

bigimage/bigImage2000.jpg

517 KB
Loading

bigimage/bigImage2000.png

943 KB
Loading

bigimage/bigImage5000.jpg

1.26 MB
Loading

bigimage/bigImage5000.png

2.26 MB
Loading

index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,14 @@ <h1>simpl.info</h1>
319319

320320
<a href="https://github.com/samdutton/simpl/blob/gh-pages/index.html" title="View source for this page on GitHub" id="viewSource">View source on GitHub</a>
321321

322+
<script>
323+
if (navigator.serviceWorker) {
324+
navigator.serviceWorker.register('sw.js').catch(function(error) {
325+
console.error('Unable to register service worker.', error);
326+
});
327+
}
328+
</script>
329+
322330
</div>
323331
<!-- container -->
324332

File renamed without changes.

lotsofimages/css/main.css

Whitespace-only changes.

lotsofimages/index.html

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!DOCTYPE html>
2+
3+
<!--
4+
Copyright 2017 Google Inc.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
<html lang="en">
20+
<head>
21+
22+
<meta name="description" content="Simplest possible examples of HTML, CSS and JavaScript." />
23+
<meta name="author" content="//samdutton.com">
24+
<meta name="viewport" content="width=device-width, initial-scale=1">
25+
<meta itemprop="name" content="simpl.info: simplest possible examples of HTML, CSS and JavaScript">
26+
<meta itemprop="image" content="/images/icons/icon192.png">
27+
<meta name="mobile-web-app-capable" content="yes">
28+
<meta id="theme-color" name="theme-color" content="#fff">
29+
30+
<base target="_blank">
31+
32+
<title>Lots of requests</title>
33+
34+
<link rel="stylesheet" href="../css/main.css" />
35+
<link rel="stylesheet" href="css/main.css" />
36+
37+
</head>
38+
39+
<body>
40+
41+
<div id="container">
42+
43+
<h1><a href="../index.html" title="simpl.info home page">simpl.info</a> Loading lots of CSS and JavaScript</h1>
44+
45+
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
46+
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/js/bootstrap.js"></script>
47+
48+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.css">
49+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-material/1.1.3/angular-material.css">
50+
51+
<p>Hello!</p>
52+
53+
<a href="https://github.com/samdutton/simpl/blob/gh-pages/lotsofjs" title="View source for this page on GitHub" id="viewSource">View source on GitHub</a>
54+
55+
</div>
56+
57+
<script src="js/main.js"></script>
58+
<script src="../js/lib/ga.js"></script>
59+
60+
</body>
61+
</html>

lotsofimages/js/main.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Copyright 2017 Google Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
'use strict';
18+

lotsofrequests/css/main.css

Whitespace-only changes.

lotsofrequests/index.html

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!DOCTYPE html>
2+
3+
<!--
4+
Copyright 2017 Google Inc.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
<html lang="en">
20+
<head>
21+
22+
<meta name="description" content="Simplest possible examples of HTML, CSS and JavaScript." />
23+
<meta name="author" content="//samdutton.com">
24+
<meta name="viewport" content="width=device-width, initial-scale=1">
25+
<meta itemprop="name" content="simpl.info: simplest possible examples of HTML, CSS and JavaScript">
26+
<meta itemprop="image" content="/images/icons/icon192.png">
27+
<meta name="mobile-web-app-capable" content="yes">
28+
<meta id="theme-color" name="theme-color" content="#fff">
29+
30+
<base target="_blank">
31+
32+
<title>Lots of requests</title>
33+
34+
<link rel="stylesheet" href="../css/main.css" />
35+
<link rel="stylesheet" href="css/main.css" />
36+
37+
</head>
38+
39+
<body>
40+
41+
<div id="container">
42+
43+
<h1><a href="../index.html" title="simpl.info home page">simpl.info</a> Loading lots of CSS and JavaScript</h1>
44+
45+
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.3/js/tether.min.js"></script>
46+
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
47+
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/js/bootstrap.js"></script>
48+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.css">
49+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-material/1.1.3/angular-material.css">
50+
51+
<p>Hello!</p>
52+
53+
<a href="https://github.com/samdutton/simpl/blob/gh-pages/lotsofrequest" title="View source for this page on GitHub" id="viewSource">View source on GitHub</a>
54+
55+
</div>
56+
57+
<script src="js/main.js"></script>
58+
<script src="../js/lib/ga.js"></script>
59+
60+
</body>
61+
</html>

lotsofrequests/js/main.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Copyright 2017 Google Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
'use strict';
18+

mediarecorder/js/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ recordButton.onclick = toggleRecording;
6060
playButton.onclick = play;
6161
downloadButton.onclick = download;
6262

63+
console.log(location.host);
6364
// window.isSecureContext could be used for Chrome
6465
var isSecureOrigin = location.protocol === 'https:' ||
65-
location.host === 'localhost';
66+
location.host.includes('localhost');
6667
if (!isSecureOrigin) {
6768
alert('getUserMedia() must be run from a secure origin: HTTPS or localhost.' +
6869
'\n\nChanging protocol to HTTPS');
@@ -138,7 +139,7 @@ function toggleRecording() {
138139

139140
// The nested try blocks will be simplified when Chrome 47 moves to Stable
140141
function startRecording() {
141-
var options = {mimeType: 'video/webm', bitsPerSecond: 100000};
142+
var options = {mimeType: 'video/mp4', bitsPerSecond: 100000};
142143
recordedBlobs = [];
143144
try {
144145
mediaRecorder = new MediaRecorder(window.stream, options);

sw.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Copyright 2017 Google Inc. All Rights Reserved.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
const FILES = [
15+
'index.html'
16+
];
17+
18+
const CACHE = 'v1';
19+
20+
self.addEventListener('install', (event) => {
21+
console.log('Service worker:', event);
22+
event.waitUntil(installHandler(event));
23+
});
24+
25+
self.addEventListener('activate', (event) => {
26+
console.log('Service worker:', event);
27+
clients.claim();
28+
});
29+
30+
self.addEventListener('fetch', (event) => {
31+
console.log('Service worker:', event);
32+
event.respondWith(fetchHandler(event.request));
33+
});
34+
35+
async function installHandler(event) {
36+
const cache = await caches.open(CACHE);
37+
cache.addAll(FILES);
38+
self.skipWaiting();
39+
}
40+
41+
async function fetchHandler(request) {
42+
const cache = await caches.open(CACHE);
43+
const cacheResult = await cache.match(request);
44+
if (cacheResult) {
45+
return cacheResult;
46+
}
47+
const fetchResult = await fetch(request);
48+
if (fetchResult.ok) {
49+
cache.put(request, fetchResult.clone());
50+
}
51+
return fetchResult;
52+
}

0 commit comments

Comments
 (0)