-
Notifications
You must be signed in to change notification settings - Fork 2
/
sw.js
74 lines (67 loc) · 1.95 KB
/
sw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
layout: null
---
var cacheName = 'build2learn-cache-v2.0';
var urlsToCache = [
'/',
'/index.html',
'/blog/',
'/manifests/manifest_webapp.json',
'/manifests/manifest_notpush.json',
'/static/img/header-home.jpg',
'/static/img/header-blog.jpg',
'/static/img/header-collab.jpg'
'/static/img/header-default.png'
'/static/img/balloon_1.png',
'/static/img/balloon_2.png',
'/static/img/logo.png',
'/static/css/main.css',
'/static/css/bootstrap-material-design.min.css',
'/static/css/bootstrap.min.css',
'/static/css/syntax.css',
'/static/css/thickbox.css',
'https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js',
'https://code.jquery.com/jquery-migrate-1.2.1.min.js',
'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js',
'https://use.fontawesome.com/18475ccca4.js',
'/static/css/projects.css'
];
{% for asset in site.static_files %}
{% if asset.path contains '/assets/images' or asset.path contains '/assets/posts' or asset.extname == '.js' %}
urlsToCache.push("{{ file.path }}")
{% endif %}
{% endfor %}
// Cache posts
{% for post in site.posts %}
urlsToCache.push("{{ post.url }}")
{% endfor %}
// Cache pages
{% for page in site.html_pages %}
urlsToCache.push("{{ page.url }}")
{% endfor %}
self.addEventListener('install', function(event) {
// Perform install steps
event.waitUntil(
caches.open(cacheName)
.then(function(cache) {
console.log('Opened cache');
return cache.addAll(urlsToCache);
})
);
});
self.addEventListener('activate', function(event) {
console.log('Finally active. Ready to start serving content!');
});
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
.then(function(response) {
// Cache hit - return response
if (response) {
return response;
}
return fetch(event.request);
}
)
);
});