Force Your Page to Always Load from the Server Not the Web Cache

You can force a page to load new every time, but should you?

Have you ever made a change to a web page file, saved that file, and uploaded it to the web server, only to then look in confusion and dismay when you visit that page in a web browser and find that the changes are not reflected in what you are seeing on your screen? While this could be because you either forgot to save the file or didn't actually upload it to the server (or uploaded it in the wrong place) another possible cause of this issue could be because the page you are seeing loaded from the web browser's cache instead of from the server where the new file is sitting.

If you are concerned about your web pages caching for your site's visitors, there is a way to tell web browsers to not cache a page, or indicate how long the browser should cache the page. This way, you can control how the browsers display your pages.

Forcing a Page to Load from the Server

You can control the browser cache with a meta tag:

<meta http-equiv="expires" content="0">

Setting the content to "0" tells the browsers to always load the page from the web server. You can also tell the browsers how long to leave a page in cache. Instead of "0", you write the date, including time, that you would like the page to be reloaded from the server. Note that the time should be in Greenwich Mean Time (GMT) and written in the format Day, dd Mon yyyy hh:mm:ss. Like this:

<meta http-equiv="expires" content="Thu, 19 Oct 2000 00:00:00 GMT">

Warning! This May Not Be a Good Idea

You may think that ensuring that a web browser always gets a page from the server, thereby ensuring that the latest version of a page is always seen, may make sense, but there is an important and useful reason why sites are loaded from cache - to improve performance.

When a webpage first loads from a server, all the resources of that page must be retrieved and sent to the browser. This means that an HTTP request must be sent to the server. The more requests a page makes for resources like CSS files, images, or other media, the slower that page will load. If a page has been visited before, the files are stored in the browser's cache.

This means than if someone visits the site again later, the browser can use the files in the cache instead of returning to the server. This speeds up the load time or a page and positively impacts site performance. In an age of mobile devices and unreliable data connections, a fast loading site is a great thing - and remember, no one ever said that a site loaded too fast!

When you force a site to load from the server instead of cache, you impact performance, so before you add these meta tags to your site, ask yourself if this is truly necessary or if the end result of ensuring the newest pages are always loaded is outweighed by the performance hit that the site will take as a result.

Edited by Jeremy Girard