tags:

views:

66

answers:

3

I have a web page written in pure HTML (with a .html extension). Whenever I edit it and push "Refresh" in my browser, the page does not get updated. However, if I change the extension to .php this problem does not occur. Could someone explain to me what's going on?

+3  A: 

Try hitting CTRL + Refresh or CTRL + F5. This should do a hard refresh and reload new content. This is only to do with Browser caching though.

There is also a specific meta tag which you can use to disable caching in the browser - see http://www.i18nguy.com/markup/metatags.html

Also, you can check your host and see if you're using static content caching on the server.

For example - you can tell IIS to cache specific files for a certain amount of time using an Expires header.

Marko
A: 

What's going on?

When you're browser downloads a .html page it saves it in what's called a browser cache so when you view that page again it saves the download time by using the cached version. The html the user receives from the request will not change unless the html file is edited on the server (a rare happening).

Why don't I get this with .php files?

When you're browser sends a request for a .php file, the server first processes that file by executing the php code contained in it. The browser cannot cache the file itself as the PHP is meant for the server to execute. If the browser cached the html it received from the request, it would defeat the entire purpose of dynamic content (the page would always contain the same data).

CrazyJugglerDrummer
Browsers can and do cache the output of dynamic pages, especially IE 6 and 7. Obviously not the PHP, but IE will cache the HTML response. Downstream proxies will often cache the response for dynamic pages, unless you have set and they obey Cache-Control and Expires headers.
Alex JL
That's basically what I thought. So, since I want to see the updates I make, should I use .php extensions on all my pages, or should I use meta tags like the above reply suggested?
George
Another thing that seems to update the page is adding an arbitrary argument to the URL, such as : page.html?12345
George
Nice one @George, Rails uses this technique for its CSS files.
Yar
A: 

Most web servers are configured to automatically add some headers to pages served by php:

Cache-Control:  no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma:         no-cache

This prevents the browser from caching the page. In order to force a reload of a page, hold down shift and hit the reload button.

DGM