<?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>Reign Drops Fall... &#187; cross-domain</title>
	<atom:link href="http://www.reigndropsfall.net/tag/cross-domain/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.reigndropsfall.net</link>
	<description>Ramblings from a hacker in Iowa</description>
	<lastBuildDate>Wed, 09 May 2012 19:48:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Using Local Modules With a Cross-Domain Dojo Build</title>
		<link>http://www.reigndropsfall.net/2010/07/07/local-modules-with-xdomain/</link>
		<comments>http://www.reigndropsfall.net/2010/07/07/local-modules-with-xdomain/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 18:58:30 +0000</pubDate>
		<dc:creator>Bryan Forbes</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[cdn]]></category>
		<category><![CDATA[cross-domain]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[xdomain]]></category>

		<guid isPermaLink="false">http://www.reigndropsfall.net/?p=1941</guid>
		<description><![CDATA[Lately, I have been using Dojo from a CDN as much as possible. There are several reasons to use a cross-domain build of Dojo that are listed here: You get more connections in MSIE, since you can load from another domain. Faster loading. You get increased cacheability/startup if many of your applications use the same [...]]]></description>
			<content:encoded><![CDATA[<p>Lately, I have been using <a href="http://dojotoolkit.org">Dojo</a> from a <abbr title="Content Delivery Network"><a href="http://en.wikipedia.org/wiki/Content_Delivery_Network">CDN</a></abbr> as much as possible.  There are several reasons to use a cross-domain build of Dojo that are listed <a href="http://docs.dojocampus.org/quickstart/cross-domain">here</a>:</p>
<ol>
<li>You get more connections in MSIE, since you can load from another domain. Faster loading.</li>
<li>You get increased cacheability/startup if many of your applications use the same installation.</li>
<li>Resource loading does not block the rest of the page from filling in as with Dojo&#8217;s normal, synchronous loading.</li>
<li>With a local install, your ISP may otherwise charge you for all of those Dojo bits that you are serving.</li>
</ol>
<p>The one problem with using a CDN is that you don&#8217;t have control over the build, which means you can&#8217;t build custom code into it.  Building custom code into a build is what most people do with builds, so it would seem you can&#8217;t develop code using Dojo&#8217;s module system against a CDN.  This couldn&#8217;t be farther from the truth.</p>
<p>In this post, we&#8217;re going to be using Dojo from <a href="http://dev.aol.com/dojo">AOL&#8217;s CDN</a>.  This method can also be used against a custom cross-domain build.  It may not seem like that would be very useful, but you may need to develop a new custom module against your build and don&#8217;t want to rebuild to test each change you make.  Let&#8217;s look at the source:</p>
<h4>xdlocal.html</h4>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>XDomain Build With Local Modules<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
		@import &quot;http://o.aolcdn.com/dojo/1.4.3/dijit/themes/tundra/tundra.css&quot;;
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
		var djConfig = {
			isDebug: true,
			parseOnLoad: true,
			baseUrl: './',
			modulePaths: {
				'my': 'my'
			}
		};
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://o.aolcdn.com/dojo/1.4.3/dojo/dojo.xd.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
		dojo.require(&quot;my.Foo&quot;);
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tundra&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">button</span> dojoType<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;my.Foo&quot;</span>&gt;</span>
		This is a &quot;my.Foo&quot; button.
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">button</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<h4>my/Foo.js</h4>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">dojo.<span style="color: #660066;">provide</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;my.Foo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
dojo.<span style="color: #660066;">require</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;dijit.form.Button&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
dojo.<span style="color: #660066;">declare</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;my.Foo&quot;</span><span style="color: #339933;">,</span> dijit.<span style="color: #660066;">form</span>.<span style="color: #660066;">Button</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
	onClick<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Button clicked!!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I have also provided a <a href="http://www.reigndropsfall.net/demos/xdlocal/xdlocal.html">live example</a> as well to show it working.  You can grab the source files in a <a href="http://www.reigndropsfall.net/demos/xdlocal.tar.bz2">tarball</a> or <a href="http://www.reigndropsfall.net/demos/xdlocal.zip">zip file</a> as well so you can play around with it.</p>
<p>The key part here is in the HTML file:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
	var djConfig = {
		isDebug: true,
		parseOnLoad: true,
		baseUrl: './',
		modulePaths: {
			'my': 'my'
		}
	};
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://o.aolcdn.com/dojo/1.4.3/dojo/dojo.xd.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p><code>djConfig</code> is used to configure Dojo upon loading.  The <code>modulePaths</code> object tells where to find the modules relative to <code>baseUrl</code>.  Changing <code>baseUrl</code> does not affect the URL used for <code>dojo</code>, <code>dijit</code>, or <code>dojox</code> because those are hard-coded in the cross-domain build.  The main thing to remember is that <code>baseUrl</code> must end in a <code>/</code>.  Given this information, we can deduce that I am telling Dojo that the <code>my</code> modules can be found at <code>http://www.reigndropsfall.net/demos/xdlocal/my/</code>.</p>
<p>As you can see from this simple example, Dojo&#8217;s module system is very versatile.  Not only can you host a build, host a custom build, host a cross-domain build, or use a CDN, but you can combine cross-domain builds with local modules which can save time and bandwidth costs.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.reigndropsfall.net/2010/08/12/dojox-charting-axis-titles/" title="Adding Axis Titles to DojoX Charts">Adding Axis Titles to DojoX Charts</a></li><li><a href="http://www.reigndropsfall.net/2010/06/15/monkey-patching/" title="Monkey patching">Monkey patching</a></li><li><a href="http://www.reigndropsfall.net/2011/01/05/internet-explorer-event-handler-leaks/" title="Internet Explorer Event Handler Leaks">Internet Explorer Event Handler Leaks</a></li><li><a href="http://www.reigndropsfall.net/2006/10/16/165/" title="Update on life">Update on life</a></li><li><a href="http://www.reigndropsfall.net/2006/06/19/and-life-keeps-flying-by/" title="And life keeps flying by">And life keeps flying by</a></li><li><a href="http://www.reigndropsfall.net/2006/04/01/my-current-endeavors/" title="My current endeavors">My current endeavors</a></li><li><a href="http://www.reigndropsfall.net/2006/01/21/updates-2/" title="Updates">Updates</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2010/07/07/local-modules-with-xdomain/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

