<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Dynamically Load CSS and JS Files</title>
	<atom:link href="http://scriptnode.com/article/dynamically-load-css-and-js-files/feed/" rel="self" type="application/rss+xml" />
	<link>http://scriptnode.com/article/dynamically-load-css-and-js-files/</link>
	<description>Tips and tricks for web developers.</description>
	<lastBuildDate>Sun, 18 Jul 2010 10:29:51 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Swarnendu De</title>
		<link>http://scriptnode.com/article/dynamically-load-css-and-js-files/comment-page-1/#comment-330</link>
		<dc:creator>Swarnendu De</dc:creator>
		<pubDate>Sun, 18 Jul 2010 10:29:51 +0000</pubDate>
		<guid isPermaLink="false">http://scriptnode.com/?p=183#comment-330</guid>
		<description>I use something like this : 

var loadJs = function(o) {
	var count = 0;
	var script;
	var files = o.scripts;
	if (!isArray(files)) {
		files = [files];
	}

	var head = document.getElementsByTagName(&#039;head&#039;)[0];

	for (var k in files) {
		script = document.createElement(&#039;script&#039;);
		script.type = &#039;text/javascript&#039;;
		if (typeof o.callback == &quot;function&quot;) {
			script.onload = function() {
				count++;
				if (count == files.length) {
					o.callback.call();
				}
			}
		}
		script.src = files[k];
		head.appendChild(script);
	}
}


And the usage : 

loadJs({
       scripts : [&#039;foo1.js&#039;, &#039;foo2.js&#039;],
       callback : function(){
              // Do something 
              // all the pages are loaded now
       }
})</description>
		<content:encoded><![CDATA[<p>I use something like this : </p>
<p>var loadJs = function(o) {<br />
	var count = 0;<br />
	var script;<br />
	var files = o.scripts;<br />
	if (!isArray(files)) {<br />
		files = [files];<br />
	}</p>
<p>	var head = document.getElementsByTagName(&#8217;head&#8217;)[0];</p>
<p>	for (var k in files) {<br />
		script = document.createElement(&#8217;script&#8217;);<br />
		script.type = &#8216;text/javascript&#8217;;<br />
		if (typeof o.callback == &#8220;function&#8221;) {<br />
			script.onload = function() {<br />
				count++;<br />
				if (count == files.length) {<br />
					o.callback.call();<br />
				}<br />
			}<br />
		}<br />
		script.src = files[k];<br />
		head.appendChild(script);<br />
	}<br />
}</p>
<p>And the usage : </p>
<p>loadJs({<br />
       scripts : ['foo1.js', 'foo2.js'],<br />
       callback : function(){<br />
              // Do something<br />
              // all the pages are loaded now<br />
       }<br />
})</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tom3k</title>
		<link>http://scriptnode.com/article/dynamically-load-css-and-js-files/comment-page-1/#comment-296</link>
		<dc:creator>tom3k</dc:creator>
		<pubDate>Mon, 22 Jun 2009 18:21:38 +0000</pubDate>
		<guid isPermaLink="false">http://scriptnode.com/?p=183#comment-296</guid>
		<description>umm, my js skills are maybe a 7/10 on a good day... but regarding the comment &#039;how can u tell if its already loaded&#039;...

cant you do somthing like

function(file,element){

if(document.getElementById(element)){

...

link.id=element;

?</description>
		<content:encoded><![CDATA[<p>umm, my js skills are maybe a 7/10 on a good day&#8230; but regarding the comment &#8216;how can u tell if its already loaded&#8217;&#8230;</p>
<p>cant you do somthing like</p>
<p>function(file,element){</p>
<p>if(document.getElementById(element)){</p>
<p>&#8230;</p>
<p>link.id=element;</p>
<p>?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Hackett</title>
		<link>http://scriptnode.com/article/dynamically-load-css-and-js-files/comment-page-1/#comment-253</link>
		<dc:creator>Matt Hackett</dc:creator>
		<pubDate>Sun, 28 Dec 2008 11:12:03 +0000</pubDate>
		<guid isPermaLink="false">http://scriptnode.com/?p=183#comment-253</guid>
		<description>@Miguel: That&#039;s odd. Works for me in XP/9.50...</description>
		<content:encoded><![CDATA[<p>@Miguel: That&#8217;s odd. Works for me in XP/9.50&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Miguel</title>
		<link>http://scriptnode.com/article/dynamically-load-css-and-js-files/comment-page-1/#comment-252</link>
		<dc:creator>Miguel</dc:creator>
		<pubDate>Sun, 28 Dec 2008 10:21:29 +0000</pubDate>
		<guid isPermaLink="false">http://scriptnode.com/?p=183#comment-252</guid>
		<description>I use this method successfully... but for some reason it seemd not to work for Opera :-( I can see the DOM node beeing created... but the styles don&#039;t load. Any ideas?</description>
		<content:encoded><![CDATA[<p>I use this method successfully&#8230; but for some reason it seemd not to work for Opera :-( I can see the DOM node beeing created&#8230; but the styles don&#8217;t load. Any ideas?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: davidm</title>
		<link>http://scriptnode.com/article/dynamically-load-css-and-js-files/comment-page-1/#comment-214</link>
		<dc:creator>davidm</dc:creator>
		<pubDate>Mon, 29 Sep 2008 15:11:59 +0000</pubDate>
		<guid isPermaLink="false">http://scriptnode.com/?p=183#comment-214</guid>
		<description>This is not near as evil as using a document.write that has an escaped out script tag as the string which happens all over the place. at least this uses javascript and correct dom manipulation</description>
		<content:encoded><![CDATA[<p>This is not near as evil as using a document.write that has an escaped out script tag as the string which happens all over the place. at least this uses javascript and correct dom manipulation</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Binny V A</title>
		<link>http://scriptnode.com/article/dynamically-load-css-and-js-files/comment-page-1/#comment-213</link>
		<dc:creator>Binny V A</dc:creator>
		<pubDate>Sun, 28 Sep 2008 19:23:50 +0000</pubDate>
		<guid isPermaLink="false">http://scriptnode.com/?p=183#comment-213</guid>
		<description>I know of this method - but I cannot bring myself to use it - for some reason, it seems really evil to me.</description>
		<content:encoded><![CDATA[<p>I know of this method &#8211; but I cannot bring myself to use it &#8211; for some reason, it seems really evil to me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ralf Lauther</title>
		<link>http://scriptnode.com/article/dynamically-load-css-and-js-files/comment-page-1/#comment-212</link>
		<dc:creator>Ralf Lauther</dc:creator>
		<pubDate>Sun, 28 Sep 2008 17:05:13 +0000</pubDate>
		<guid isPermaLink="false">http://scriptnode.com/?p=183#comment-212</guid>
		<description>js frameworks like mootools offer this feature!</description>
		<content:encoded><![CDATA[<p>js frameworks like mootools offer this feature!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dav Glass</title>
		<link>http://scriptnode.com/article/dynamically-load-css-and-js-files/comment-page-1/#comment-211</link>
		<dc:creator>Dav Glass</dc:creator>
		<pubDate>Sun, 28 Sep 2008 15:58:39 +0000</pubDate>
		<guid isPermaLink="false">http://scriptnode.com/?p=183#comment-211</guid>
		<description>Yeah, loading them is the easy part. Now finding out when they are loaded so you can use them is the hard part.

That&#039;s where YUI&#039;s Get Utility comes in handy:
http://developer.yahoo.com/yui/get/

It will fire an event when the files have been loaded so you know that you can use them.</description>
		<content:encoded><![CDATA[<p>Yeah, loading them is the easy part. Now finding out when they are loaded so you can use them is the hard part.</p>
<p>That&#8217;s where YUI&#8217;s Get Utility comes in handy:<br />
<a href="http://developer.yahoo.com/yui/get/" rel="nofollow">http://developer.yahoo.com/yui/get/</a></p>
<p>It will fire an event when the files have been loaded so you know that you can use them.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
