Posted By
Christopher Dabhi
on
17. September 2013 04:13
Recently, one of our clients experienced a problem that many website developers confront from time to time. Does this problem sound familiar? You upload fresh, new content to a web page – something you want visitors, old and new, to see. Yet many visitors only see an older, outdated version of the same page. Their browsers are ignoring the new page and instead displaying a previously cached version of the same page – much to the chagrin of both the visitor and website manager.

It’s a frustrating problem, but caching web pages is a feature that is intended to be useful. By temporarily storing web documents, network traffic is reduced along with bandwidth usage and server load. Pages are loaded faster for the user, and the website is subject to less visitor stress.
How Web Caching Works
Web caching works by passing a requested URL through a web cache. If certain conditions are satisfied, the browser displays the web page from the cache. Otherwise, it sends a request to serve to load and display the new web page information.
There are a few common rules that determine whether the cached page is used. Secure pages (HTTPS) are not cached. Also, the response headers in the page determine whether to cache a web document or not. There are three cache controls in the HTTP – freshness , validation, and invalidation:
- Freshness – Determined by the value set in the “Expires” response header
- Validation – A conditional request that can be made using the “if-modified-since” header to check any change in value if the response has a “Last Modified” header. An ETag in the header section can also be used to allow strong or weak validation.
- Invalidation – This occurs when a URL associated with the cached response gets a POST, PUT, or DELETE request.
Failed Attempts Using Tags
While caching has many advantages, our client was becoming frustrated that new information available on the server was being ignored by browsers that repeatedly fetched data from the cache. We tried various methods to resolve this web page cache, but all in vain:
- Attempt #1: Cache-Control Directive – Cache-Control: NO-CACHE indicates that a fresh request should be forwarded to the server and cached information should not be used.
- Attempt #2: Expires – The “Expires” tag saves server trips. Instead of checking with the server every time for a version update, Expires sets up an expiration date of the page for the browser to check.
- Attempt #3: Max-Age – An even simpler tag than “Expires” that sets the expiration time in seconds.
However, none of these methods worked 100% of the time with the different versions of Internet Explorer.
Alternative Approaches:
While we treading other ways of resolving this issue, we stumbled upon other approaches, among them were –
- Last-Modified – This method tells the browser what version of the document it is sending. The server responds with a date along with the file. So every time when the browser checks with the server if there is a new version of the file available since the last time.
- ETag – Using this unique identifier, often known as fingerprinting (this may be in the form of content or file version), every file gets a unique fingerprint each time it is modified.
Obtaining Unique URL
What did work? We found there was a need to call unique URL every time; so that browsers always saw the page as new each time it was encountered. This could be achieved with two methods that required adding unique pseudo parameters to the URL, one by using a random number and another by adding a timestamp.
- Using Math.random

This code is placed at the top of the page within the tag. The variable ‘random number’ is then appended to the URL of the page, which generates a random number each time the page is encountered by the browser.
- Appending a TimeStamp
This method works the same way as Math.random but appends the current time instead of a random number. So what if the page is requested twice in the same minute? The code actually returns a new value every millisecond so even if the page is requested twice in the same minute it will still have different URL.
We chose to resolve the issue using the ‘TimeStamp’ approach and succeeded. In case you are facing a similar problem feel free to try any of these methods.
Call us at 484-892-5713 or Contact Us today to know more how we overcome web page caching with simple and innovative solution with client satisfaction.