Force Your Page to Always Load From the Server, Not the Web Cache

person at computer
(Kelvin Murray/Getty Images)

Have you ever made a change to a website page only to then look in confusion and dismay when the changes are not reflected in the browser? Perhaps you forgot to save the file or didn't actually upload it to the server (or uploaded it in the wrong place). Another possibility, however, is that the browser is loading the page from its cache rather than the server where the new file is sitting.

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

Forcing a Page to Load from the Server

You can control the browser cache with a meta tag:

<meta http-equiv=“Pragma” content=”no-cache”>
<meta http-equiv=“Expires” content=”-1″>
<meta http-equiv=“CACHE-CONTROL” content=”NO-CACHE”>

Setting the to 0 tells the browser to always load the page from the web server. You also can tell the browser how long to leave a page in cache. Instead of 0 , enter the date, including the 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

Warning: This May Not Be a Good Idea

You may think that turning off the web browser's cache for your page may make sense, but there is an important and useful reason 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 such as CSS files, images, and other media, the slower that page will load. If a page has been visited before, the files are stored in the browser's cache. 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 and improves site performance. In an age of mobile devices and unreliable data connections, fast loading is imperative. After all, no one has ever complained that a site loads too fast.

Bottom line: When you force a site to load from the server instead of the cache, you affect performance. Therefore, before you add these meta tags to your site, ask yourself if this is truly necessary and worth the performance hit that the site will take as a result.