Can you please tell me how to configure browser cache for statics and media in Django

screenshot of the test from google

here's google help .. developers.google.com/speed/docs/insights/LeverageBrowserCaching

I set up caching of the file system by the djbook.ru/rel1.8/topics/cache.html#filesystem-caching manual

those. added to settings

CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', 'LOCATION': '/var/tmp/django_cache', } } 

and

 MIDDLEWARE_CLASSES = ( 'django.middleware.cache.UpdateCacheMiddleware', .... 'django.middleware.cache.FetchFromCacheMiddleware', ) 

When loading pages appeared Expires in the title.

But how to make it for files from static and media is not clear ..

    1 answer 1

    Django should not be responsible for installing static headers. This should be answered by the server that will serve it, for example, Nginx or Apache.

    On the local machine, your django services your stitics (most likely), but as written in the manual, this is extremely inefficient in terms of performance.

    For clarity, the picture work looks like this. The http request comes -> Nginx determines the type of request - if it is static, then it gives it itself, if not it gives it to the standing application -> because Django communicates with the server using the wsgi protocol, then the django itself serves (starts) another application, for example uWSGI (uWSGI implementation of the wsgi protocol) -> request comes to django itself. The answer goes up the chain. Now it becomes clear why it is so inefficient and why django should not do it.

    Decide on who will serve the statics on the battle server, and read in this direction.

    • one
      Thank you) now it is clear) on my hosting .. Technical support said it would turn on) - Vladimir