<?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>Stephen Gray&#039;s dev blog &#187; external</title>
	<atom:link href="http://blog.s-gray.com/tag/external/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.s-gray.com</link>
	<description>e-commerce and integrations</description>
	<lastBuildDate>Sun, 17 Jan 2010 09:32:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>jQuery loading remote/external javascript files using getScript()</title>
		<link>http://blog.s-gray.com/2008/09/22/jquery-loading-external-javascript-files-using-getscript/</link>
		<comments>http://blog.s-gray.com/2008/09/22/jquery-loading-external-javascript-files-using-getscript/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 08:57:22 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[external]]></category>
		<category><![CDATA[getScript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[remote]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=109</guid>
		<description><![CDATA[I found out that jQuery has a nice little method for loading external scripts into the page at run time called getScript(). It basically gets the contents of the external file using an AJAX request and then eval()s the code at runtime, which seems like a perfect way of doing it. I reckon it's much better than appending new &#60;script&#62; tags to the &#60;head&#62; tag as well.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working over the weekend on a site and I got to the part of writing the client side MVC using jQuery (because I love the idea now!).</p>
<p>I found out that jQuery has a nice little method for loading external scripts into the page at run time called getScript(). It basically gets the contents of the external file using an AJAX request and then eval()s the code at runtime, which seems like a perfect way of doing it. I reckon it&#8217;s much better than appending new &lt;script&gt; tags to the &lt;head&gt; tag as well.</p>
<p>The only issue is that it can take some time to load an external file so you can&#8217;t always run functions from within that file straight away. Thankfully there is a workaround for this using another jQuery method. You basically set all AJAX request to be synchronous before you run getScript() and then set AJAX requests to be asynchronous again after the script is loaded. If you end up loading like 20 files at the beginning of a page load this could take a while but hopefully you won&#8217;t be doing that <img src='http://blog.s-gray.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p109code1'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1091"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p109code1"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajaxSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>async<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$.<span style="color: #660066;">getScript</span><span style="color: #009900;">&#40;</span>MVCRoot<span style="color: #339933;">+</span>fileName<span style="color: #339933;">+</span><span style="color: #3366CC;">'.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$.<span style="color: #660066;">ajaxSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>async<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><a href="http://docs.jquery.com/Ajax/jQuery.getScript">And here&#8217;s some more info on this lovely little function <img src='http://blog.s-gray.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2008/09/22/jquery-loading-external-javascript-files-using-getscript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

