Django and service workers - serve “sw.js” at application's root url

前端 未结 4 2165
闹比i
闹比i 2020-12-06 01:56

So I\'m building a Django progressive web app with offline support using service workers.

According to google\'s documentation, the sw.js file should be at the root

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 02:16

    I was getting all the time the error DOMException: The script resource is behind a redirect, which is disallowed.

    I spent hours trying to figure out the solution.

    Apart from adding at urls.py:

    from django.views.generic import TemplateView
    
    urlpatterns = [
      ...,
      url(r'^service-worker.js', (TemplateView.as_view(template_name="service-worker.js", content_type='application/javascript', )), name='service-worker.js'),
    ]
    

    There was also another step needed. Instead of

    
    

    I used:

    
    

提交回复
热议问题