Skip to content

Commit 7b41ef7

Browse files
committed
fix: add baseurl to serviceworker template
1 parent 252a9a2 commit 7b41ef7

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

docs/serviceWorker.js.liquid

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@ permalink: /serviceWorker.js
99
var newCacheName = 'pouchdb-assets-cache-v{{ site.time }}';
1010

1111
var criticalAssets = [
12-
'/offline.html',
13-
'/static/css/pouchdb.min.css',
12+
'{{ site.baseurl }}/offline.html',
13+
'{{ site.baseurl }}/static/css/pouchdb.min.css',
1414
];
1515

1616
{%- assign pages = collections.pages | where_exp: "page", "page.url != '/manifest.appcache'" -%}
1717
{% assign guides = collections.guides %}
1818

1919
var pages = [
20-
{% for page in pages %}'{{ page.url | replace:'index.html','' }}',
21-
{% endfor %}{% for page in guides %}'{{ page.url | replace:'index.html','' }}'{% unless forloop.last %},{% endunless %}
20+
{% for page in pages %}'{{ site.baseurl }}{{ page.url | replace:'index.html','' }}',
21+
{% endfor %}{% for page in guides %}'{{ site.baseurl }}{{ page.url | replace:'index.html','' }}'{% unless forloop.last %},{% endunless %}
2222
{% endfor %}];
2323

2424
var blogPosts = [{% for page in collections.posts %}
25-
'{{ page.url | replace:'index.html','' }}',{% endfor %}
25+
'{{ site.baseurl }}{{ page.url | replace:'index.html','' }}',{% endfor %}
2626
];
2727

2828
// Only cache the first blog page
2929
var nonCriticalAssets =
3030
[
31-
'/static/favicon.ico',
32-
'/static/js/code.min.js',
31+
'{{ site.baseurl }}/static/favicon.ico',
32+
'{{ site.baseurl }}/static/js/code.min.js',
3333
'https://code.jquery.com/jquery.min.js',
3434
'https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js',
3535
'https://cdn.jsdelivr.net/npm/pouchdb/dist/pouchdb.min.js',
@@ -80,7 +80,7 @@ self.addEventListener('activate', function (event) {
8080
self.addEventListener('fetch', function (event) {
8181
// Ignore POST etc, which will happen when using PouchDB
8282
// in the browser console
83-
if(event.request.method === "GET") {
83+
if (event.request.method === "GET") {
8484
// Ignore requests from browser extensions etc
8585
if ((event.request.url.indexOf('http') === 0)) {
8686
// Try the cache, if it's not in there try the network, then cache that response
@@ -92,7 +92,7 @@ self.addEventListener('fetch', function (event) {
9292
cache.put(event.request, response.clone());
9393
return response;
9494
}).catch(function () {
95-
return cache.match('/offline.html');
95+
return cache.match('{{ site.baseurl }}/offline.html');
9696
});
9797
});
9898
})

0 commit comments

Comments
 (0)