views:

64

answers:

2

I have a joomla application working on Apache.To improve site performace we have written a .htaccess file to root of the application with setting a far future expires header to all the static content. As desired first time the files load in fresh with 200 status code. when again click on the same link many of the files are served directly from cache. I need explanation for two things

  1. When i press f5 then a number of files load with 304 status code however i expected them to be coming directly from cache without hitting the server for a status header?

  2. When i close the browser and come back to the same page again i see the same thing happening a number of files load with 304 status code although i thought they will load directly from the browser cache?

I understand that 304 also serves file from browser cache but i want to avoid the header communication between servers as my static files wont ever change. Also i want to add that my requests are over a https connection does that create any issue.

A: 

Using a secure session may indeed cause a problem with caching.

For security many browsers do not cache SSL data except during the SSL session. When the browser or tab is closed the SSL cache is flushed out.

Firefox has a config option to control this. I don't know about IE. It's also possible that there is some Cache-Control header that will override this behavior.

The Cache-Control header is, I believe, HTTP/1.1 and you should use it as well as Expires. Cache-Control offers more features for controlling the cache.

Zan Lynx
You should be definitely be setting Cache-Control. Expires is probably optional - most of the HTTP 1.0 clients now are probably robots / scripts that aren't going to obey caching anyway.
AngerClown
A: 

Browsers have algorithms for sending requests for cached content, based on the expires time. Usually, content with a far future header will never be reloaded like you expect. But, hitting reload or F5 ignores this and forces a page reload of all page content.

What you want to do to test this is put your cursor back in the address bar (ALT-d on Win) and hit Enter. This is like re-visting the page and the browser should behave like you expect.

AngerClown