4

I was profiling the performance of my web application using Google's Page Speed plugin for Firebug and one of the things it says is that I should 'leverage caching' — "The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources". When I dug deeper I found that all request for static files to the Django WSGI server lacked the Expires and the Cache-Control headers. Who should add these headers — should Django do it? If so, how?

Thanks.

1
  • static files should be served by either apache/lighthttpd/... what ever web server you are using... Commented Oct 21, 2010 at 6:53

1 Answer 1

7

Any static files you may have for your page should be served by your web server, e.g. Apache. Django should never be involved unless you have to prevent access of some files to certain people.

Here, I found an example of how to do it:

# our production setup includes a caching load balancer in front.
# we tell the load balancer to cache for 5 minutes.
# we can use the commented out lines to tell it to not cache,
# which is useful if we're updating.
<FilesMatch "\.(html|js|png|jpg|css)$">
ExpiresDefault "access plus 5 minutes"
ExpiresActive On
#Header unset cache-control:
#Header append cache-control: "no-cache, must-revalidate"
</FilesMatch>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.