Skip to content

Commit 128ee29

Browse files
committed
Improve SW cache busting
1 parent 0934896 commit 128ee29

2 files changed

Lines changed: 48 additions & 8 deletions

File tree

offline.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
---
22
layout: page
3-
title: "Oops! It Looks Like Your Connection Is Offline"
3+
title: "Oops! It Looks Like Your’re Offline"
44
page-class: page--offline
55
meta: "CSS Wizardry’s offline content"
66
permalink: /offline/
77
---
88

9-
It looks as though your device is offline. You’ll probably want to check back
10-
when you have a connection, but until then you can:
9+
It looks as though your device is offline. Not to worry; I’ve prepared some
10+
offline content for you to read whilst you wait for your connection to come
11+
back:
1112

1213
* [head to the homepage](/);
1314
* [read a little more about CSS Wizardry](/about/);
14-
* [learn about the services I offer](/services/), or;
15+
* [learn about the services I offer](/services/);
16+
* [see what I’ve done for other companies](/case-studies/), or;
1517
* [find out how best to get in touch with me](/contact/).
1618

1719
Or if you’d like to read something:
1820

19-
* [Case Study: Ocado Workshop](/case-studies/ocado-workshop/)
2021
* [Pragmatic, Practical, and Progressive Theming with Custom Properties](/2016/10/pragmatic-practical-progressive-theming-with-custom-properties/)
2122
* [Mixins Better for Performance](/2016/02/mixins-better-for-performance/)
2223
* [More Transparent UI Code with Namespaces](/2015/03/more-transparent-ui-code-with-namespaces/)

sw.js

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1-
var cacheName = 'csswizardry:0003';
1+
var cacheName = 'csswizardry:0005';
22
var cacheFiles = [
33
'/',
44
'/about/',
55
'/services/',
66
'/contact/',
7-
'/offline/',
7+
'/case-studies/',
8+
'/case-studies/raspberry-pi-code-club-workshop/',
9+
'/case-studies/ocado-workshop/',
10+
'/case-studies/nhs-nhsx-elearning-platform/',
11+
'/case-studies/better-collective/',
12+
'/case-studies/madgex-consultancy-workshop/',
13+
'/case-studies/bbc-workshop/',
14+
'/case-studies/bskyb/',
15+
'/case-studies/css-wizardry/',
16+
'/case-studies/financial-times/',
817
'/2015/03/more-transparent-ui-code-with-namespaces/',
918
'/2015/08/bemit-taking-the-bem-naming-convention-a-step-further/',
1019
'/2016/02/mixins-better-for-performance/',
1120
'/2016/10/pragmatic-practical-progressive-theming-with-custom-properties/',
12-
'/case-studies/ocado-workshop/'
21+
'/offline/'
1322
];
1423

24+
25+
26+
27+
1528
self.addEventListener('install', function(event) {
1629
event.waitUntil(
1730
caches.open(cacheName)
@@ -22,6 +35,10 @@ self.addEventListener('install', function(event) {
2235
);
2336
});
2437

38+
39+
40+
41+
2542
self.addEventListener('fetch', function(event) {
2643
event.respondWith(
2744
caches.match(event.request)
@@ -37,3 +54,25 @@ self.addEventListener('fetch', function(event) {
3754
})
3855
);
3956
});
57+
58+
59+
60+
61+
62+
// Empty out any caches that don’t match the ones listed.
63+
self.addEventListener('activate', function(event) {
64+
65+
var cacheWhitelist = ['csswizardry:0005'];
66+
67+
event.waitUntil(
68+
caches.keys().then(function(cacheNames) {
69+
return Promise.all(
70+
cacheNames.map(function(cacheName) {
71+
if (cacheWhitelist.indexOf(cacheName) === -1) {
72+
return caches.delete(cacheName);
73+
}
74+
})
75+
);
76+
})
77+
);
78+
});

0 commit comments

Comments
 (0)