<?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>Jens Arps &#187; Framework Peace</title>
	<atom:link href="http://jensarps.de/category/framework-peace/feed/" rel="self" type="application/rss+xml" />
	<link>http://jensarps.de</link>
	<description></description>
	<lastBuildDate>Tue, 01 May 2012 12:00:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>EmbedJS 0.2 and AMD</title>
		<link>http://jensarps.de/2011/10/17/embedjs-0-2-and-amd/</link>
		<comments>http://jensarps.de/2011/10/17/embedjs-0-2-and-amd/#comments</comments>
		<pubDate>Mon, 17 Oct 2011 14:44:36 +0000</pubDate>
		<dc:creator>Jens Arps</dc:creator>
				<category><![CDATA[EmbedJS]]></category>
		<category><![CDATA[Framework Peace]]></category>
		<category><![CDATA[AMD]]></category>
		<category><![CDATA[CommonJS]]></category>
		<category><![CDATA[embedjs]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[uxebu]]></category>

		<guid isPermaLink="false">http://jensarps.de/?p=352</guid>
		<description><![CDATA[[Note: This is a cross-post. I also published this on the uxebu blog.]During JSConf.eu, we released EmbedJS 0.2. That release was mainly about a fundamental architectural change: the move to the AMD pattern for our features. Let me explain why we decided to do this, why we think this is a big step forward and [...]]]></description>
			<content:encoded><![CDATA[<p>[<em>Note: This is a cross-post. I also published this on the <a href="http://uxebu.com/blog/2011/10/17/embedjs-0-2-and-amd/" target="_blank">uxebu blog</a>.</em>]</p><p>During JSConf.eu, we released EmbedJS 0.2. That release was mainly about a fundamental architectural change: the move to the AMD pattern for our features. Let me explain why we decided to do this, why we think this is a big step forward and what this means for the user.</p>
<p><span id="more-352"></span></p>
<h2>Modules</h2>
<p>AMD stands for “Asynchronous Module Definition”. So, what are modules? I’ll quote the definition from the <a href="http://wiki.commonjs.org/wiki/Modules/1.1" target="_blank">CommonJS Module specification</a>, as it describes it very well:</p>
<blockquote><p>This specification addresses how modules should be written in order to be interoperable among a class of module systems that can be both client and server side, secure or insecure, implemented today or supported by future systems with syntax extensions. These modules are offered privacy of their top scope, facility for importing singleton objects from other modules, and exporting their own API.</p></blockquote>
<p>So, modules are isolated parts of code that live in their own scope and are kind of self-contained. Well, that is pretty much how we see the individual Features in EmbedJS – we made our feature implementations as small as possible and reduced dependencies as much as possible. Many of EmbedJS’ features are also browser-independent, so why not make it possible to use some of the tools in a non-browser environment?</p>
<p>(If you want to learn more on modules and why we need them, I recommend <a href="http://twitter.com/briancavalier" target="_blank">@briancavalier</a>‘s <a href="http://briancavalier.com/presentations/pgh-js-amd-10-2011/" target="_blank">presentation on modules</a>.)</p>
<h2>Features in EmbedJS</h2>
<p>So far, I didn’t really explain what I mean with “Features”, so let me do another quote, this time from the <a href="http://uxebu.github.com/embedjs/" target="_blank">Project Page</a>:</p>
<blockquote><p>EmbedJS uses the concept of features: Functionalities are split up into features, as fine-grained as possible, and each feature might have multiple implementations.</p></blockquote>
<p>Our Features are kinda small and contain only few methods, sometimes even just one. The asyc-promise feature, for example, will get you Promises, and the transport-jsonp feature will get you a method for pull in data via jsonp – and that’s it.  If multiple methods are contained within one feature, this is because they are too closely related to each other to split them up, like the html-class feature, which contains the <code><span class="text">addClass</span></code>, <code><span class="text">removeClass</span></code>, <code><span class="text">toggleClass</span></code> and <code><span class="text">hasClass</span></code> methods.</p>
<h2>AMD vs CommonJS Modules 1.1</h2>
<p>Now that we knew modules were the way to go, there was another, quite important question to solve: There are two common patterns for modules, so which one do we want to apply? One pattern is described in the above mentioned CommonJS Wiki, the other pattern is described in the <a href="https://github.com/amdjs/amdjs-api/wiki/AMD" target="_blank">AMD wiki</a>.</p>
<p>Well, there have been <a href="http://tagneto.blogspot.com/2011/04/on-inventing-js-module-formats-and.html" target="_blank">some</a> <a href="http://unscriptable.com/index.php/2011/09/30/amd-versus-cjs-whats-the-best-format/" target="_blank">blog</a> <a href="http://blog.millermedeiros.com/2011/09/amd-is-better-for-the-web-than-commonjs-modules/" target="_blank">posts</a> lately that compare the pros and cons of each of them, so I don’t want to repeat all of this – but I’m hiving a similar tendency towards AMD. Besides this, there was another big reason to go with AMD: Remember, EmbedJS is based on the <a href="http://dojotoolkit.org/" target="_blank">Dojo Toolkit</a>, and it’s a <a href="http://dojofoundation.org/" target="_blank">Dojo Foundation Project</a> – and we hope that the efforts that went into making EmbedJS might flow back into the Dojo Toolkit one day. And as the Dojo Toolkit uses the AMD approach, the decision was quickly made to do so as well.</p>
<h2>Implications for EmbedJS</h2>
<p>There are several huge benefits for EmbedJS in using the AMD approach. The most noteworthy surely is the ease-of-use for developers. In your code, when you find you want an EmbedJS method, you <a href="http://uxebu.github.com/embedjs/docs/" target="_blank">look up the feature name</a> that provides this method, add it to the require statement and there you go. Man, easy.</p>
<p>A second important thing is that EmbedJS now plays really nice with AMD based projects. In fact, you could see EmbedJS now as a collection of small useful modules, that can be easily integrated – and also easily extended.</p>
<p>The third major benefit is that we can now get rid of all the custom tools we built around EmbedJS – you can load features with any AMD loader (though we use and recommend RequireJS) and build it with any AMD optimizer/builder (we recommend r.js).</p>
<p>Let’s have an extra word on</p>
<p><strong>Building</strong></p>
<p>It was always possible with EmbedJS to create a custom build that would contain only the features you wanted/needed in your project. But, you had to use our build tool that we created. And learning using Yet-Another-Build-Tool™ is always… well, let’s just say it would be cool to avoid it (and, not to forget, so is maintaining it). We did a lot to improve that, we created a GUI that allowed you to just “click together” the features you wanted, and we worked on a dynamic loader that would ease development. But still, the situation was far from ideal, and people just ended up going for our ready-made “kitchensink” builds that contained <em>all</em> of the features.</p>
<p>Now, we still provide those ready-made builds that contain only the implementations for a given platform (and are stripped of require/define calls), but I really hope that using the AMD approach and using an AMD optimizer to deploy will become the more adopted style.</p>
<h2>Q: Cross-target? A: The Feature Plugin</h2>
<p>One goal of EmbedJS is to allow for easy cross-device development. We got rid of run-time branching but instead went for an approach that held the different implementations for a given feature in separate files, so that one only has to deploy the actually needed code to a given device – and not all the alternate implementations, that sit useless in the device’s memory and never get used. We needed to achieve that with “in-house” means provided by the AMD approach. Lucky us, there’s the concept of <a href="https://github.com/amdjs/amdjs-api/wiki/Loader-Plugins" target="_blank">loader-plugins</a>, and so I created a <a href="https://github.com/jensarps/AMD-feature" target="_blank">feature-plugin for AMD loaders</a>. The idea is simple yet effective: You create an implementation map that maps a feature name to an implementation, and if there are multiple implementations, you supply tests that tells the plugin which feature to use.</p>
<p>When you’re ready to deploy, you have two choices: I f you really don’t know on what target your code is going to end up, you can use the dynamic implementation map containing the tests for the optimizer, and you’ll get a build that contains all of the available implementations. Then, during runtime, the feature plugin will run the tests and load the specific implementation. But, if you <em>do</em> know what target your code will run on, you provide a specific implementation map that doesn’t contain tests but directly maps to the according implementations, and you will only have those in your built file.</p>
<h2>Synopsis</h2>
<p>AMD is exactly what we needed to make EmbedJS more what we want it to be – an easy to use JavaScript toolbox that is especially handy for cross-target scenarios such as cross-platform mobile development. So, please don’t hesitate and check it out on Github, read the project page and check out the examples!</p>
<p><strong>Resources / Further Reading</strong></p>
<ul>
<li><a href="https://github.com/uxebu/embedjs" target="_blank">EmbedJS on GitHub</a></li>
<li><a href="http://uxebu.github.com/embedjs/" target="_blank">EmbedJS Project Page</a></li>
<li><a href="http://uxebu.github.com/embedjs/docs/" target="_blank">EmbedJS API Docs</a></li>
<li><a href="https://github.com/jensarps/AMD-feature" target="_blank">AMD-Feature plugin</a></li>
<li><a href="https://github.com/amdjs/amdjs-api/wiki" target="_blank">AMD Wiki</a></li>
<li><a href="http://wiki.commonjs.org/wiki/CommonJS" target="_blank">CommonJS Wiki</a></li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://jensarps.de/2011/10/17/embedjs-0-2-and-amd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>dojox.analytics.Urchin for jQuery</title>
		<link>http://jensarps.de/2009/10/03/dojox-analytics-urchin-for-jquery/</link>
		<comments>http://jensarps.de/2009/10/03/dojox-analytics-urchin-for-jquery/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 17:28:41 +0000</pubDate>
		<dc:creator>Jens Arps</dc:creator>
				<category><![CDATA[Framework Peace]]></category>
		<category><![CDATA[Goodies to go]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[tracking]]></category>

		<guid isPermaLink="false">http://jensarps.de/?p=38</guid>
		<description><![CDATA[Or: Still ending the ga.js wait… It has become quiet here the last weeks – due to an awesome trip to Italy. Returning home, I decided to put Google Analytics on this page. As I always hate waiting for the ga.js to load while visiting websites, I wanted a mechanism to delay the load of [...]]]></description>
			<content:encoded><![CDATA[<p>Or: <em>Still</em> ending the ga.js wait…</p>
<p>It has become quiet here the last weeks – due to an awesome trip to Italy. Returning home, I decided to put Google Analytics on this page.</p>
<p>As I always hate waiting for the ga.js to load while visiting websites, I wanted a mechanism to delay the load of it. Why this is a good idea has been discussed often enough elsewhere, so we take it as fact. Peter Higgins once <a href="http://higginsforpresident.net/2008/06/google-analytics-after-onload/" target="_blank">wrote such a wrapper for dojo</a>, and as of dojo 1.3, it&#8217;s officially included in dojox (see <a href="http://alex.dojotoolkit.org/2009/04/ending-the-gajs-wait/" target="_blank">Alex Russel&#8217;s post</a>). But this WordPress theme runs jQuery, and I didn&#8217;t want to have two frameworks in one website – so I searched for something that did the job for jQuery.<br />
<span id="more-38"></span><br />
But I didn&#8217;t really find what I was looking for. Well, there <em>are</em> some jQuery plugins that provide functionality like I wanted. Some were overpowered, some poorly written – and in the end, they all relied on jQuery.getScript(). The problem is, that getScript() adds a random parameter to the GET call, so that the called script is never cached. While this <em>may</em> be useful for some situations, in this case it&#8217;s really annoying and undesireable. In addition, I liked the idea of dojox.analytics.Urchin to not really <em>wait</em> for the script to be loaded, but instead to go see every now and then if the _gat global variable is present, and to give up after some time in case something went wrong.</p>
<p>So I decided to &#8220;port&#8221; dojox.analytics.Urchin to jQuery. It works almost the same as it&#8217;s dojo origin, with two major differences: First, you can&#8217;t have several instances of it running, you call it directly via jQuery.urchin.load(args). Second, there&#8217;s an option waitForDOM, set to true as default, that delays the loading of ga.js until the DOM is ready. If you call jQuery.urchin.load() from within a jQuery(document).ready() block, set this to false.</p>
<p>Example? Here you go:</p>
<pre>&lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="jquery.urchin.js"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;
jQuery.urchin.load({acct:'UA-111111-1'});
&lt;/script&gt;</pre>
<p>Or, if you need more options:</p>
<pre>&lt;script type="text/javascript"&gt;
$(document).ready(function() {
    // do some stuff
    // ...
    // load ga.js
    $.urchin.load({
        acct:'2234-2342',
        timeout: 8000,
        waitForDOM: false
    });
});
&lt;/script&gt;</pre>
<p>You can get the file here: <a href="http://jensarps.de/tests/jquery_analytics/jquery.urchin.js" target="_blank">jquery.urchin.js</a></p>
<p>Uncompressed version: <a href="http://jensarps.de/tests/jquery_analytics/jquery.urchin.uncompressed.js">jquery.urchin.uncompressed.js</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jensarps.de/2009/10/03/dojox-analytics-urchin-for-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

