Where to put the service worker and manifest in the django project?

I plan to convert the django project to a Progressive Web App. I cannot figure out where to place the service_worker.js and manifest.json files in my django project. I tried the following:

Myproject /

|__app1 |__app2 |__manage.py |__manifest.json |__service_worker.js 

and then tried to register the service worker from the html file using the relative path .. /../../service_worker.js. This did not work. He showed this error: "Upon receipt of the script."

HTTP error code (404) was received

Another approach I tried is to put service_worker.js and manifest.json in the static folders:

Myproject /

 |__app1/ |__static/ |__app1/ |__service_worker.js |__manifest.json |__app2 |__manage.py 

and access them using {% static 'app1 / service_worker.js'%}. The problem with this approach is that the scope of the registered service_worker.js is limited to this static folder. I saw in one stackoverflow answer that I can explicitly specify the working worker area as {scope: '/'}. But I think there may be a better approach that I am missing. Please let me know if anyone has a solution.

+5
source share
1 answer

It looks like you want to have a common SW for your entire application (1, 2). You can have both SW and manifest.json in the root of the project, link the manifest to the project home page. If you want to cache all the way, setting up a scope is not a bad idea since it has been officially registered here. Find the "Register your employee" section on the page associated with it.

0
source

Source: https://habr.com/ru/post/1276243/


All Articles