Skip to content

Commit b047b0a

Browse files
committed
test sw
1 parent 3f37ac8 commit b047b0a

5 files changed

Lines changed: 39 additions & 6 deletions

File tree

‎cache.manifest‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CACHE MANIFEST
2-
# Build: 20170522081657
2+
# Build: 20170522082001
33

44
CACHE:
55
resources/fonts/Dressedless_Three.svg

‎gulpfile.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ gulp.task("dist:appjs", function() {
9191
gulp.task("dist:swjs", function() {
9292
return gulp.src(['./static/app/src/sw.js'])
9393
.pipe(cachebust.references())
94-
.pipe(gulp.dest('./src/'));
94+
.pipe(gulp.dest('./'));
9595
});
9696
gulp.task('dist:html', function () {
9797
return gulp.src(['./static/app/*.html'])

‎index.html‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎static/app/html/scripts.html‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
<script>
1313
if ('serviceWorker' in navigator) {
1414
window.addEventListener('load', function() {
15-
navigator.serviceWorker.register('src/sw.js', {
16-
scope: '/codelf-sw/'
17-
}).then(function(registration) {
15+
navigator.serviceWorker.register('sw.js').then(function(registration) {
1816
// Registration was successful
1917
console.log('ServiceWorker registration successful with scope: ', registration.scope);
2018
}, function(err) {

‎sw.js‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Here comes the install event!
2+
// This only happens once, when the browser sees this
3+
// version of the ServiceWorker for the first time.
4+
self.addEventListener('install', function(event) {
5+
// We pass a promise to event.waitUntil to signal how
6+
// long install takes, and if it failed
7+
event.waitUntil(
8+
// We open a cache…
9+
caches.open('simple-sw-v1').then(function(cache) {
10+
// And add resources to it
11+
return cache.addAll([
12+
'src/lib/all.207da233.js'
13+
]);
14+
})
15+
);
16+
});
17+
18+
// The fetch event happens for the page request with the
19+
// ServiceWorker's scope, and any request made within that
20+
// page
21+
self.addEventListener('fetch', function(event) {
22+
// Calling event.respondWith means we're in charge
23+
// of providing the response. We pass in a promise
24+
// that resolves with a response object
25+
event.respondWith(
26+
// First we look for something in the caches that
27+
// matches the request
28+
caches.match(event.request).then(function(response) {
29+
// If we get something, we return it, otherwise
30+
// it's null, and we'll pass the request to
31+
// fetch, which will use the network.
32+
return response || fetch(event.request);
33+
})
34+
);
35+
});

0 commit comments

Comments
 (0)