title: Django and service workers - serve "sw.js" at application's root url
body: <p>So I'm building a Django progressive web app with offline support using service workers.</p>
  
  <p>According to <a href="https://developers.google.com/web/fundamentals/getting-started/your-first-offline-web-app/step-5?hl=en" rel="noreferrer">google's documentation</a>, the sw.js file should be at the root of the app's url:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>At the moment, I'm serving all static assets from <a href="http://example.com/static/" rel="noreferrer">http://example.com/static/</a> folder. But I need to serve this specific file at a url like: <a href="http://example.com/sw.js" rel="noreferrer">http://example.com/sw.js</a>.</p>
  
  <p>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?</p>
  
  <p><strong>Note</strong>: I've seen <a href="https://stackoverflow.com/questions/11232922/django-staticfiles-at-url-root">this question</a> which suggests using the static() method from <code>django.conf.urls.static</code>. But <a href="https://docs.djangoproject.com/en/1.9/howto/static-files/" rel="noreferrer">django's docs</a> say that the static method is only for development use so not good for me.</p>
  
  <p><strong>Note (2)</strong>: I guess I could change the <code>STATIC_URL</code> 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.</p>