May 2, 2013

f Comment

Why Is My Browser Cache Not Working? I am using Chrome, Firefox, Internet Explorer.

Amazon Suppose you configure your web server to tell the browser that it needs to cache your webpage for a specified amount of time but it does not work, there could be a number of causes.

If you want to know whether your web browser is using its browser cache read my post on How Do I Know If My Web Browser Is Using Its Browser Cache?
Cause 1: Did your web server use the correct HTTP headers?
For all intents and purposes you should use Cache-Control for browser cache control purposes. Do not use Pragma. Suppose your web server is Apache 2.2.21 you should have the following in your httpd.conf:

LoadModule headers_module modules/mod_headers.so
Header set Cache-Control "max-age=2592000"
Header unset Pragma

The value of max-age is in seconds. When browser sends an HTTP request to your web server the HTTP response headers may look like the following:

Cache-Control:max-age=2592000
Connection:Keep-Alive
Content-Type:text/html
Date:Thu, 02 May 2013 06:41:48 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.2.21 (Win32) PHP/5.3.10
Transfer-Encoding:chunked
X-Powered-By:PHP/5.3.10

Use Chrome or Firefox's web developer tool to view the HTTP response headers. If you see Cache-Control with a large max-age you should be good.

If you use Nginx simply include 'expires 1y;' in the server configuration file to mean your webpages won't expire until one year later.
Cause 2: Is your browser using a hard refresh?
If you use Chrome a big gotcha is the way you navigate to the webpage matters. If you hit F5 or click Refresh button you are doing a hard refresh, and Chrome will NEVER use its browser cache.

You need to enter some random URL in the URL text field and press Enter, then enter http://www.mensfashionforless.com/t-shirt.html in the URL text field and press Enter. This gives Chrome a chance to use its browser cache.

Another way to give Chrome a chance to use its browser cache is click on a link on the currently rendered webpage.

Firefox and Internet Explorer, on the other hand, are more lenient than Chrome in that it's easier to give Firefox and IE a chance to use its browser cache. Simply click on the URL text field and press Enter.

When browser uses their browser cache to render the webpage the browser will NOT talk to the remote server. I've verified this behavior with IE (version is 9.0.8112.16421), Firefox (version is 20.0), Chrome (version is 26.0.1410.64 m) by turning off my web server and navigating to a cached URL pointing to my server in these browsers.
If you want to know whether your web browser is using its browser cache read my post on How Do I Know If My Web Browser Is Using Its Browser Cache?
If you have any questions let me know and I will do my best to help you!
Please leave a comment here!
One Minute Information - by Michael Wen
ADVERTISING WITH US - Direct your advertising requests to Michael