Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

questions about expires header

  1. if there is no expires http header set in the response , what does it mean for browsers?
  2. In Glassfish v3, how to configure expires header for static resources that have been deployed under docroot not as a war file?
  3. I noticed that Glassfish seems to set ETag header by default. Is that true? The ultimate goal I want to achieve here is to set a far future expires header but be able to tell browsers "there is new stuff" whenever new version of css, js, image files are deployed.

Thanks so much for any advices.

like image 555
Bobo Avatar asked Feb 25 '23 08:02

Bobo


2 Answers

Read http://blogs.msdn.com/b/ie/archive/2010/07/14/caching-improvements-in-internet-explorer-9.aspx for background.

  1. If you don't specify freshness, some browsers will check every time. Some will check once-per-session. Most latest version browsers will try to calculate a heuristic expiration of 10% of the time since the Last-Modified date, if provided. If not, they'll check every time or once per session.
  2. No idea.
  3. That's not how HTTP expiration works-- the browser won't magically "know" that new content appeared on the server (how could it?). If you want to change content that's cached on the client, you will need to change your URLs so that the old cached content is ignored.
like image 72
EricLaw Avatar answered Feb 26 '23 20:02

EricLaw


For expires not provided in header of the server response, see §14.21 here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

Even when provided, expires is overriden by the max-age directive, thus if expires is not provided max-age is used. If none are provided, then see §13.2.4 here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.2.4 Basically it says the client can set cache for an undetermined period of time, and not consistently.

To solve your problem, you may say your static elements never expire, and add an expire time to the included elements of a HTML doc. To do that, see here: http://www.tipsandtricks-hq.com/how-to-add-far-future-expires-headers-to-your-wordpress-site-1533

Quoted: "To add expires header to the image, CSS, javascript files add the following to your .htaccess file

Expire Header

> <FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf)$">
> ExpiresDefault "access plus 2 hours"
> </FilesMatch>

or Expire images header

> ExpiresActive On 
> ExpiresDefault A0
> ExpiresByType image/gif A2592000

[...] Keep in mind that when you use expires header the files are cached in the browser until it expires so do not use this on files that changes frequently. If you change/update a file that has a far future expiry (eg. CSS or javascript files) then you should rename that file and use the renamed version so the browser doesn’t fetch the old file."

like image 40
mins Avatar answered Feb 26 '23 20:02

mins