<?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>TLS Web Solutions &#187; lazy load jQuery</title>
	<atom:link href="http://www.tlswebsolutions.com/tag/lazy-load-jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tlswebsolutions.com</link>
	<description></description>
	<lastBuildDate>Mon, 05 Jul 2010 15:58:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to include jQuery dynamically, aka, check to see if it exists</title>
		<link>http://www.tlswebsolutions.com/how-to-include-jquery-dynamically-aka-check-to-see-if-it-exists/</link>
		<comments>http://www.tlswebsolutions.com/how-to-include-jquery-dynamically-aka-check-to-see-if-it-exists/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 08:30:07 +0000</pubDate>
		<dc:creator>Tim Selaty</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[!window.jQuery]]></category>
		<category><![CDATA[check if jquery]]></category>
		<category><![CDATA[define jquery]]></category>
		<category><![CDATA[dynamic jquery]]></category>
		<category><![CDATA[jquery does not exist]]></category>
		<category><![CDATA[jquery not defined]]></category>
		<category><![CDATA[lazy load jQuery]]></category>

		<guid isPermaLink="false">http://www.tlswebsolutions.com/?p=386</guid>
		<description><![CDATA[I cannot tell you how many times I&#8217;ve walked into a project that required the following: Fancy JavaScript [...]]]></description>
			<content:encoded><![CDATA[<p>I cannot tell you how many times I&#8217;ve walked into a project that required the following:</p>
<ol>
<li>Fancy JavaScript alerts, dialogs, and validation.</li>
<li>JavaScript assets that will distributed to subsites / satellite sites.</li>
<li>Of these sites, some may or may not already have these assets already defined.</li>
</ol>
<p>What I&#8217;m referring to specifically is jQuery. While building a tasty and user-friendly form.. I needed a way to check to see if jQuery didn&#8217;t exist, and if it didn&#8217;t include it dynamically by append it to the HEAD tag. This is commonly referred to &#8216;including jQuery dynamically&#8217;. Often times different phrases such as &#8216;check to see if jQuery is defined&#8217;, &#8216;lazy load jQuery&#8217;, &#8216;!window.jQuery&#8217;</p>
<p>Here is the JavaScript code to make the magic happen.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;color: #003d68;"><span style="color: #000066; font-weight: bold;color: #000080;">if</span><span style="color: #009900;color: #000080;">&#40;</span><span style="color: #339933;color: #000080;">!</span><span style="color: #009900;color: #000080;">&#40;</span>window.<span style="color: #660066;">jQuery</span> <span style="color: #339933;color: #000080;">&amp;&amp;</span> window.<span style="color: #660066;">jQuery</span>.<span style="color: #660066;">fn</span>.<span style="color: #660066;">jquery</span> <span style="color: #339933;color: #000080;">==</span> <span style="color: #3366CC;color: #000080;">'1.3.2'</span><span style="color: #009900;color: #000080;">&#41;</span><span style="color: #009900;color: #000080;">&#41;</span> <span style="color: #009900;color: #000080;">&#123;</span><span style="color: #003366; font-weight: bold;color: #000080;">var</span> s <span style="color: #339933;color: #000080;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;color: #000080;">&#40;</span><span style="color: #3366CC;color: #000080;">'script'</span><span style="color: #009900;color: #000080;">&#41;</span><span style="color: #339933;color: #000080;">;</span>s.<span style="color: #660066;">setAttribute</span><span style="color: #009900;color: #000080;">&#40;</span><span style="color: #3366CC;color: #000080;">'src'</span><span style="color: #339933;color: #000080;">,</span> <span style="color: #3366CC;color: #000080;">'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'</span><span style="color: #009900;color: #000080;">&#41;</span><span style="color: #339933;color: #000080;">;</span>s.<span style="color: #660066;">setAttribute</span><span style="color: #009900;color: #000080;">&#40;</span><span style="color: #3366CC;color: #000080;">'type'</span><span style="color: #339933;color: #000080;">,</span> <span style="color: #3366CC;color: #000080;">'text/javascript'</span><span style="color: #009900;color: #000080;">&#41;</span><span style="color: #339933;color: #000080;">;</span>document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;color: #000080;">&#40;</span><span style="color: #3366CC;color: #000080;">'head'</span><span style="color: #009900;color: #000080;">&#41;</span><span style="color: #009900;color: #000080;">&#91;</span><span style="color: #CC0000;color: #000080;">0</span><span style="color: #009900;color: #000080;">&#93;</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;color: #000080;">&#40;</span>s<span style="color: #009900;color: #000080;">&#41;</span><span style="color: #339933;color: #000080;">;</span><span style="color: #009900;color: #000080;">&#125;</span></pre></div></div>

<p>As a recap, here is what the snippet above does. &#8220;Check to see if jQuery is defined. If it&#8217;s not, grab jQuery from Google&#8217;s API and include it in the HEAD tag&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tlswebsolutions.com/how-to-include-jquery-dynamically-aka-check-to-see-if-it-exists/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
