3

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.

Rihards
  • 759
  • 2
  • 12
  • 22

3 Answers3

0

The If-Modified-Since request-header field is used with a method to make it conditional: if the requested variant has not been modified since the time specified in this field, an entity will not be returned from the server; instead, a 304 (not modified) response will be returned without any message-body.

   If-Modified-Since = "If-Modified-Since" ":" HTTP-date

An example of the field is:

   If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT

A GET method with an If-Modified-Since header and no Range header requests that the identified entity be transferred only if it has been modified since the date given by the If-Modified-Since header. The algorithm for determining this includes the following cases:

you already have the max-age so that will apply as well

you want to cache and also get conditional GET so no response is sent to the client

silviud
  • 2,677
  • 2
  • 16
  • 19
0

Silviud is talking about a header that is sent by the client as part of the request to the server so that the server knows whether to send a 304 Not Modified or the entire content of the file/page as a response.

While removing the Server header will do no harm, it won't do that much good either except for the case of tiny (e.g., Not Modified) responses. You may want to consider adding "public" to your Cache-control header to explicitly state that shared caches may cache the content.

David
  • 1,012
  • 6
  • 9
0

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

Sameer
  • 4,070
  • 2
  • 16
  • 11