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 of the app's url:
You need to do this because the scope of a service worker (the set of urls that the ServiceWorker will load for) is defined by the directory where it resides.
At the moment, I'm serving all static assets from http://example.com/static/ folder. But I need to serve this specific file at a url like: http://example.com/sw.js.
Any idea how I can achieve this? I could make a specific nginx rule to do this redirection, but I don't know if it's the cleanest way of doing this. Maybe this setting should reside in urls.py?
Note: I've seen this question which suggests using the static() method from django.conf.urls.static
. But django's docs say that the static method is only for development use so not good for me.
Note (2): I guess I could change the STATIC_URL
setting, but I'm happy with my files being served from /static directory. I only want this one file to be at url's root.