views:

34

answers:

1

Good afternoon, I need that results of my Servlet always cached by browser. Trying to put the same headers like http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js but the results still do not come from the browser cache (tested with FireBug).

My code:

 response.setContentType("text/javascript");
  response.setHeader("Last-Modified", "Mon, 15 Feb 2010 23:30:12 GMT");
  response.setHeader("Date", "Tue, 28 Sep 2010 19:45:24 GMT");
  response.setHeader("Expires", "Wed, 28 Sep 2021 19:45:24 GMT");
  response.setHeader("Vary", "Accept-Encoding");
  response.setHeader("X-Content-Type-Options", "nosniff");
  response.setHeader("Cache-Control", "public, max-age=31536000");
  response.setHeader("Age", "36");

My headers (firebug):

HTTP/1.1 200 OK
Content-Type: text/javascript; charset=UTF-8
Last-Modified: Mon, 15 Feb 2010 23:30:12 GMT
Date: Sun, 10 Oct 2010 14:40:49 GMT
Expires: Mon, 10 Oct 2011 14:40:49 GMT
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Server: sffe
Content-Encoding: gzip
Cache-Control: public, max-age=31536000
Content-Length: 46401
Age: 2

Googleapis headers:

HTTP/1.1 200 OK
Content-Type: text/javascript; charset=utf-8
Last-Modified: Mon, 15 Feb 2010 23:30:12 GMT
Expires: Wed, 28 Sep 2021 19:45:24 GMT
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Cache-Control: public, max-age=31536000
Age: 36
Content-Encoding: gzip
Date: Sun, 10 Oct 2010 14:32:06 GMT
Server: Google Frontend
Content-Length: 36838

All headers are the same, but with different order (even though the code - should not, apparently GAE reverses the order). In what may be the problem? Thanks.

+1  A: 

Ordering doesn't matter. Do you have problems with it? In theory, it can happen if the servletcontainer used by GAE uses a HashMap to store the headers before committing to the response and your local servletcontainer a LinkedHashMap or a List<Pair>.

As to the response caching, you need at least a far-future Expires header along with a valid ETag or Last-Modified header. The Cache-Control and Age are not necessary.

BalusC
I can't change order. As a result, the headers on the output is almost identical, but FireFox for some reason refuses to cache scripts. A working example: http://static.metabus.ru/js/join.js?jquery-1.4.2.min.js,jquery.mousewheel-3.0.js When updating this URL with FireBug I can see that browser each time loads data. But http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js each time is taken from cache.
chardex
It get correctly cached here. Your problem lies somewhere else. Aren't you doing a "hard refresh" using Ctrl+F5 or so?
BalusC
No, just F5. How do you determine that the result is correctly cached?
chardex
Firebug *Net* panel tells that no request was been sent when I hit Enter on address bar once again.
BalusC