diff --git a/brutaldon/templates/base.html b/brutaldon/templates/base.html
index 8d6e2fd..bdf8fc9 100644
--- a/brutaldon/templates/base.html
+++ b/brutaldon/templates/base.html
@@ -222,8 +222,8 @@
} else {
//Register the ServiceWorker
- navigator.serviceWorker.register('{% static "js/pwabuilder-sw.js" %}', {
- scope: '{% url 'home' %}'
+ navigator.serviceWorker.register('pwabuilder-sw.js', {
+ scope: '{% url '' %}'
}).then(function(reg) {
console.log('Service worker has been registered for scope:'+ reg.scope);
});
diff --git a/brutaldon/static/js/pwabuilder-sw.js b/brutaldon/templates/pwabuilder-sw.js
similarity index 89%
rename from brutaldon/static/js/pwabuilder-sw.js
rename to brutaldon/templates/pwabuilder-sw.js
index ba84f32..52a0fc0 100644
--- a/brutaldon/static/js/pwabuilder-sw.js
+++ b/brutaldon/templates/pwabuilder-sw.js
@@ -1,8 +1,9 @@
//This is the "Offline page" service worker
+{% load static %}
//Install stage sets up the offline page in the cache and opens a new cache
self.addEventListener('install', function(event) {
- var offlinePage = new Request('offline.html');
+ var offlinePage = new Request('{% static "offline.html" %}');
event.waitUntil(
fetch(offlinePage).then(function(response) {
return caches.open('pwabuilder-offline').then(function(cache) {
@@ -19,7 +20,7 @@ self.addEventListener('fetch', function(event) {
fetch(event.request).catch(function(error) {
console.error( '[PWA Builder] Network request Failed. Serving offline page ' + error );
return caches.open('pwabuilder-offline').then(function(cache) {
- return cache.match('/static/offline.html');
+ return cache.match('{% static "offline.html" %}');
});
}
));
diff --git a/brutaldon/urls.py b/brutaldon/urls.py
index 2796065..a1d0e67 100644
--- a/brutaldon/urls.py
+++ b/brutaldon/urls.py
@@ -57,5 +57,6 @@ urlpatterns = [
path('search', views.search, name='search'),
path('search_results', views.search_results, name='search_results'),
path('emoji', views.emoji_reference, name='emoji'),
- path('', views.home),
+ path('pwabuilder-sw.js', views.service_worker, name="sw"),
+ path('', views.home, name=''),
]
diff --git a/brutaldon/views.py b/brutaldon/views.py
index 0c9373b..2e5d5dc 100644
--- a/brutaldon/views.py
+++ b/brutaldon/views.py
@@ -782,3 +782,6 @@ def emoji_reference(request):
{"preferences": account.preferences,
"emojos": sorted(emojos, key=lambda x: x['shortcode']),
'own_acct' : request.session['user']})
+
+def service_worker(request):
+ return render(request, 'pwabuilder-sw.js', content_type="application/javascript")