from django.conf import settings from django.shortcuts import render def manifest(request): return render(request, "pwa/manifest.webmanifest", content_type="application/manifest+json") def service_worker(request): context = {"cache_version": settings.EVECTION_PWA_CACHE_VERSION} response = render(request, "pwa/sw.js", context, content_type="application/javascript") # A service worker's own scope covers everything below where it's # served from, but the browser also independently refuses a broader # Service-Worker-Allowed scope than the response's own URL path # implies unless this header says otherwise. Being served at exactly # "/sw.js" already gives it root scope, so this is just explicit. response["Service-Worker-Allowed"] = "/" return response def offline(request): return render(request, "pwa/offline.html")