Nginx – What headers to add for most efficient file caching

cachenginxstatic-files

So I've this response header for static files on my nginx server.

Cache-Control:max-age=2592000
Connection:keep-alive
Date:Sat, 11 Dec 2010 22:28:13 GMT
Expires:Mon, 10 Jan 2011 22:28:13 GMT
Last-Modified:Sat, 11 Dec 2010 22:11:35 GMT
Server:nginx/0.6.32

I think of removing the server signature to reduce the response size.
What should I add in my server configuration to make the browser to use files not even making a request to server and overall make it as efficient as possible?
Currently I could get the js on server this fast: http://i55.tinypic.com/orrons.png

Edit:
I know added this property: add_header cache-control public;
And the response headers are like this:

Cache-Control: max-age=31536000
Cache-Control: public

Because I've the expires 1y; set too. Is there a way to join them?

Also I checked facebook javascript file responses and they use these techniques:

HTTP/1.1 200 OK
Content-Type: application/x-javascript; charset=utf-8
Last-Modified: Sat, 01 Jan 2000 00:00:00 GMT
Pragma:
Content-Encoding: gzip
X-Cnection: close
Content-Length: 11724
Vary: Accept-Encoding
Cache-Control: public, max-age=31239788
Expires: Thu, 08 Dec 2011 23:43:19 GMT
Date: Sun, 12 Dec 2010 10:00:11 GMT
Connection: keep-alive

What did the Vary property do? I think I will apply the last-modified for years ago as they did.

Best Answer

This is not related to caching but since you are comparing your headers to that of facebook I assume your concern is to improve the user experience of your site.

One this I see missing from your header is compression. nginx and other Webservers allow you to compress the content before sending it to the client, significantly reducing the amount total data transfer.

You can use the link below to configure compression on your instance of nginx.

http://www.devcha.com/2010/02/enable-gzip-compression-of-nginx.html

When doing compression be sure to handle older MSIE browsers which don't handle compression very well. There is more info in a Related post

Secondly, if possible use a different domain for your static content. This will reduce the client request size because the cookie will not be passed. Example Yahoo used yimg.com for its static content i.e JS,CSS, images

Related Topic