<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Henry&#039;s Web Notes &#187; JavaScript</title>
	<atom:link href="http://devel.lubong.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://devel.lubong.com</link>
	<description>My dev notes about the web</description>
	<lastBuildDate>Wed, 12 Aug 2009 06:18:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JavaScript: How To Force Page To Reload</title>
		<link>http://devel.lubong.com/2007/06/24/javascript-how-to-force-page-to-reload/</link>
		<comments>http://devel.lubong.com/2007/06/24/javascript-how-to-force-page-to-reload/#comments</comments>
		<pubDate>Sun, 24 Jun 2007 18:02:22 +0000</pubDate>
		<dc:creator>Henry Lubong</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[refresh]]></category>
		<category><![CDATA[reload]]></category>

		<guid isPermaLink="false">http://devel.lubong.com/2007/06/24/javascript-how-to-force-page-to-reload/</guid>
		<description><![CDATA[When you want to load a page on a browser, you would normally click the Refresh / Reload button or press F5 or CTRL-R on your keyboard. If you set your browser to cache previously viewed pages, doing a normal page reload will cause the browser to fetch the requested page from cache unless otherwise [...]]]></description>
			<content:encoded><![CDATA[<p>When you want to load a page on a browser, you would normally click the Refresh / Reload button or press F5 or CTRL-R on your keyboard. If you set your browser to cache previously viewed pages, doing a normal page reload will cause the browser to fetch the requested page from cache unless otherwise instructed by a script or meta tag in the page. When this happens, images and css will be read from cache and form fields will also retain their values (this included text, textarea, radio button and checkbox). </p>
<p>In order to completely force a page to reload, which means, instructing the browser to skip the cached data and re-fetch everything from the server, you need to press CTRL-F5 on IE and Firefox or Command-R on Mac-Safari.</p>
<p>In JavaScript, there are also different ways to reload a page. Here are the methods for a normal page reload:</p>
<p><code>window.location.assign(url);</code><br />
Loads the page at the the provided URL.</p>
<p><code>window.location.replace(url);</code><br />
Same as <code>assign()</code> method except that when <code>replace()</code> is used, the current page will not be saved in the session history as it was replaced by the provided URL.</p>
<p><code>document.location = url;</code><br />
Technically, location is a read-only property of the document. But some browsers allow you to assign a URL to it, which causes the page to reload. The reason for this is because whenever the location property is modified, a page will reload with the new assigned URL. I recommend using <code>window.location</code> for browser compatibility.</p>
<p><code>window.location.href = url;</code><br />
Same as <code>document.location</code></p>
<p>The other properties of location that when modified will reload the page are <code>hash, host, hostname, pathname, port, protocol and search</code>.</p>
<p><strong>What if you want to completely force a page to reload?</strong> Say, you want to clear all entered values in a form or maybe you have modified your CSS and you want to make sure that the page will pickup the new changes. In order to do so, you can do the following:</p>
<p><code>window.location.reload(true);</code></p>
<p>The <code>reload</code> method accepts a boolean value, which, when it is <code>true</code>, causes the page to always fetch document from the server. When none is specified, it defaults to <code>false</code>, which may reload the page from its cache.</p>
<p>As you can see, the methods for forcing a page to reload has their own purposes. If you simply want to reload the  page and do not care about displaying fresh data, you should not always force it to reload from the server to avoid making http requests, which is an expensive call and a waste of bandwidth. You are not only calling the page itself but you maybe reloading an external CSS page too.</p>
]]></content:encoded>
			<wfw:commentRss>http://devel.lubong.com/2007/06/24/javascript-how-to-force-page-to-reload/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

