WWW FAQs: What is "caching?"

2004-04-29: Caching refers to the strategy of keeping a copy of a page or image you have already seen; web browsers typically cache files that they display for you, and simply ask the server if the page has actually changed rather than always downloading the entire thing. This speeds up your next visit to the page.

Since caching everything forever would take up too much space, web browsers typically delete the least recently used file in the cache when a certain total cache size is reached.

Caching also occurs in other places. You may be using a proxy server, in which case the proxy server is probably caching pages on behalf of you and other users to save trips to the real Internet.

Users typically become aware of caching when things don't work as expected. For instance, you might make a change to your own web page, open up your web page in your web browser, and not see the change until you click the "reload" button, telling your browser to discard the cached copy of that page.

Of course, some things, such as credit card transactions, should not be cached. Fortunately, the HTTP protocol that web browsers and servers use to communicate includes ways for the web server to specify how long a page may be safely cached, if at all. But sometimes browsers do not perfectly obey such directives. The problem that is made worse by the tendency of websites built in PHP, ASP or other dynamic web programming languages to tell the web browser not to cache anything. This problem is not inherent to those languages, but it is a common result of poorly-thought-out site design.

Caching can potentially be a privacy issue for those who share their computers; cached copies of pages on your hard drive can reveal information about your browsing habits.

Legal Note: yes, you may use sample HTML, Javascript, PHP and other code presented above in your own projects. You may not reproduce large portions of the text of the article without our express permission.

Got a LiveJournal account? Keep up with the latest articles in this FAQ by adding our syndicated feed to your friends list!