silviolleite / django-pwa

Looks like an app, feels like an app, but IS NOT an app.
MIT License
541 stars 112 forks source link

service-worker.js loading is Unconventional #73

Open rcmurphy opened 3 years ago

rcmurphy commented 3 years ago

service-worker.js is in the templates directory, which would lead one to believe that they can override it. However, the file is actually loaded in directly as a plain file. Would you be open to a PR to change the behavior to use template based loading? With caching, the performance difference would be non-existent after the first request, and it would allow for some more powerful customization of the logic within that file.

PetrDlouhy commented 3 years ago

I have easily overridden this by adding

    path('serviceworker.js', TemplateView.as_view(template_name='serviceworker.js', content_type='application/javascript'), name='service-worker'),

to my urls.py (before django-pwa).

But some kind of support from django-pwa would be nice, since it would be common request to generate some of the filesToCache automatically. Having it in template with reasonable blocks defined or having it configurable some other way would also spare us a lot of code copying and duplication.