Django: remove 'Vary: cookie' response header for static files
<p>I am using Django to serve static files (dev, localhost only). I want these files to be cached by the browser, but they aren't. I therefore added Middleware to change the response header for /static/ urls as described here <a href="https://stackoverflow.com/questions/7013735/turn-off-caching-of-static-files-in-django-development-server">Turn off caching of static files in Django development server</a> (They were fixing the opposite issue, but also by changing the header).</p>

<p>The issue is that the files are still not being cached. I believe this is because of the 'Vary: Cookie' header. How do I get rid of this header? It seems to be added sometime after my Middleware StaticCache is executed.</p>

<p>Response header of static files in browser:</p>

<pre><code>Cache-Control:public, max-age=315360000
Content-Length:319397
Content-Type:application/javascript
Date:Mon, 22 Aug 2016 13:34:04 GMT
Expires:Sun, 17-Jan-2038 19:14:07 GMT
Last-Modified:Fri, 19 Aug 2016 23:18:48 GMT
Server:WSGIServer/0.1 Python/2.7.10
Vary:Accept-Encoding, Cookie
</code></pre>

<p>settings.py</p>

<pre><code>MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    '&lt;app&gt;.middleware.BeforeViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    '&lt;app&gt;.middleware.StaticCache', 
    '&lt;app&gt;.middleware.ExceptionMiddleware',
)
</code></pre>

<p>middleware.py</p>

<pre><code>class StaticCache(object):
    def process_response(self, request, response):
        if request.path.startswith('/static/'):
            response['Cache-Control'] = 'public, max-age=315360000'
            response['Vary'] = 'Accept-Encoding'
            response['Expires'] = 'Sun, 17-Jan-2038 19:14:07 GMT'
        return response
</code></pre>

<p>urls.py</p>

<pre><code>url(r'^static/(?P&lt;path&gt;.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
</code></pre>