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?
views:
66answers:
3Try 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.
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).
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.