Commit e7db83ed authored by Julien Enselme's avatar Julien Enselme

Rely on project version to set SW version

We create a new class view to handle the SW and pass proper context to the template.
parent 28d59244
from django.http import Http404
from django.shortcuts import render
from django.views.generic import TemplateView
from djangopwa import version
def offline(request):
......@@ -20,3 +23,14 @@ def say_something(request, key):
raise Http404(f'{key} is not a valid thing to say')
return render(request, 'pwa/say_something.html', context={'thing': things_to_say[key]})
class ServiceWorkerView(TemplateView):
template_name = 'sw.js'
content_type = 'application/javascript'
name = 'sw.js'
def get_context_data(self, **kwargs):
return {
'version': version,
}
const VERSION = '1.0.0';
const VERSION = '{{ version }}';
const staticCachePrefix = 'static';
const staticCacheName = `${staticCachePrefix}-${VERSION}`;
const dynamicCacheName = 'dynamic';
......
......@@ -15,8 +15,8 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path
from django.views.generic import TemplateView
from . import version
from .apps.pwa import views as pwa_views
......@@ -32,7 +32,7 @@ urlpatterns = [
# trick to make it work.
path(
'sw.js',
TemplateView.as_view(template_name='sw.js', content_type='application/javascript'),
name='sw.js',
pwa_views.ServiceWorkerView.as_view(),
name=pwa_views.ServiceWorkerView.name,
),
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment