Commit 506bfa75 authored by Julien Enselme's avatar Julien Enselme

Add view that must never be cached

parent c81e1288
......@@ -5,6 +5,8 @@ import time
from django.http import Http404
from django.shortcuts import render
from django.urls import reverse
from django.utils import timezone
from django.views.decorators.cache import never_cache
from django.views.generic import TemplateView
from djangopwa import version
......@@ -25,6 +27,7 @@ def my_page(request):
'Say something invalid': reverse('say_something', kwargs={'key': 'invalid'}),
'Response in random time': reverse('random_response'),
'Fill dynamic cache': reverse('fill_dynamic_cache', kwargs={'id': 1}),
'Must not cache': reverse('must_not_cache'),
}
return render(request, 'pwa/my_page.html', context={'routes': routes})
......@@ -54,6 +57,11 @@ def fill_dynamic_cache(request, id):
return render(request, 'pwa/fill_dynamic_cache.html', context={'id': id})
@never_cache
def must_not_cache(request):
return render(request, 'pwa/must_not_cache.html', context={'requested_at': timezone.now()})
class ServiceWorkerView(TemplateView):
template_name = 'sw.js'
content_type = 'application/javascript'
......
{% extends 'base.html' %}
{% block title %}Must not cache{% endblock %}
{% block body %}
<h1>Must not cache</h1>
<p>Requested: {{ requested_at | date:"Y-m-d H:s:s" }}</p>
{% endblock %}
......@@ -28,6 +28,7 @@ urlpatterns = [
path('say-something/<str:key>', pwa_views.say_something, name='say_something'),
path('random-response', pwa_views.random_response, name='random_response'),
path('fill-dynamic-cache/<int:id>', pwa_views.fill_dynamic_cache, name='fill_dynamic_cache'),
path('must-not-cache', pwa_views.must_not_cache, name='must_not_cache'),
# The service worker cannot be in /static because its scope will be limited to /static.
# Since we want it to have a scope of the full application, we rely on this TemplateView
......
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