<?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>Über Software &#187; javascript</title>
	<atom:link href="http://www.uebersoftware.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.uebersoftware.com</link>
	<description>Opinions and thoughts on Software and Technology.</description>
	<lastBuildDate>Thu, 29 Apr 2010 06:04:30 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Website deployments: Plain old Ant</title>
		<link>http://www.uebersoftware.com/2009/10/website-deployments-plain-old-ant/</link>
		<comments>http://www.uebersoftware.com/2009/10/website-deployments-plain-old-ant/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 20:26:29 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Web2.0]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[webapps]]></category>

		<guid isPermaLink="false">http://www.uebersoftware.com/?p=150</guid>
		<description><![CDATA[In the last entry I was mentioning several solutions for managing web site deployments and packaging for php webapps. Since with PHP there is usually no build process already at development time this has often to be established especially for test &#038; production &#8211; and yes there needs to be a build process if you [...]]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://www.uebersoftware.com/2009/10/initialise-external-javascript-in-page-fragments/">last entry</a> I was mentioning several solutions for managing web site deployments and packaging for php webapps. Since with PHP there is usually no build process already at development time this has often to be established especially for test &#038; production &#8211; and yes there needs to be a build process if you do serious php web development.</p>
<p>Despite Sprocket or similar tools I decided to go for the plain old ANT approach. Why? It was the most practical tool, you have full control of what you are doing and the other tools did not quite what I wanted.</p>
<p>One part of this ant solution was to configure production setting in several source files. I rediscovered just how powerful and really simple this great tool is. Once you get used to is configure,combine,pack and deploy your php/js/html/css is a piece of cake:</p>
<p>Here some excerpts<br />
In order to have just one source file I defined some custom preprocessor variables in my various files:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//@@prod@@ $config['base_dir']=&quot;&quot;;</span>
<span style="color: #666666; font-style: italic;">/*@@dev@@*/</span> <span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'base_dir'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Foo/&quot;</span><span style="color: #339933;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;!--@@js-dev-start@@ --&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;assets/js/jquery.plugin1.js&quot;&gt;&lt;/script&gt;
&lt;script type='text/javascript' src='assets/js/jquery.plugin2.js'&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;assets/js/jquery.plugin3.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;assets/js/jquery.plugin4.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;assets/js/jquery.plugin5.js&quot;&gt;&lt;/script&gt;
&lt;!-- @@js-dev-end@@ --&gt;
&lt;!-- @@js-prod-start@@ &lt;script type=&quot;text/javascript&quot; src=&quot;assets/js/jsbuild.js&quot;&gt;&lt;/script&gt; @@js-prod-end@@ --&gt;</pre></div></div>

<p>then in ant this looks as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;Configuring PHP config for production&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;replaceregexp</span> <span style="color: #000066;">byline</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">flags</span>=<span style="color: #ff0000;">&quot;m&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;regexp</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;^.*@@dev@@.*$&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;substitution</span> <span style="color: #000066;">expression</span>=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${build.dir}&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;php/config/*.php&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/replaceregexp<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;replaceregexp</span> <span style="color: #000066;">byline</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">flags</span>=<span style="color: #ff0000;">&quot;m&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;regexp</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;^.*@@prod@@(.*)$&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;substitution</span> <span style="color: #000066;">expression</span>=<span style="color: #ff0000;">&quot;\1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${build.dir}&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;php/config/*.php&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/replaceregexp<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>And for the javascript in my php &#8211; view files</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;Configuring referenced Javascript for production&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;replaceregexp</span> <span style="color: #000066;">flags</span>=<span style="color: #ff0000;">&quot;sg&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;regexp</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;@@js-dev-start@@[^\@]*@@js-dev-end@@&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;substitution</span> <span style="color: #000066;">expression</span>=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${build.dir}/php/view&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;**/*.php&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/replaceregexp<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;replaceregexp</span> <span style="color: #000066;">byline</span>=<span style="color: #ff0000;">&quot;true&quot;</span>  <span style="color: #000066;">flags</span>=<span style="color: #ff0000;">&quot;m&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;regexp</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;^.*@@js-prod-start@@(.*)@@js-prod-end@@.*$&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;substitution</span> <span style="color: #000066;">expression</span>=<span style="color: #ff0000;">&quot;\1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${build.dir}/php/view&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;**/*.php&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/replaceregexp<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Applying the concat task for js and css concatenation and apply java to invoke the yuicompressor and you&#8217;re done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.uebersoftware.com/2009/10/website-deployments-plain-old-ant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Initialise External Javascript in Page Fragments</title>
		<link>http://www.uebersoftware.com/2009/10/initialise-external-javascript-in-page-fragments/</link>
		<comments>http://www.uebersoftware.com/2009/10/initialise-external-javascript-in-page-fragments/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 19:03:27 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.uebersoftware.com/?p=136</guid>
		<description><![CDATA[In the last couple of hours I was contemplating around maintainable, performant and non-obstrusive Javascript on a project I am working on.
Following situation:
- Much Inline Javascript
- Many JS and CSS files referenced
- No Frontend Deployment/Build Process in place
- Some Javascript values are set at page generation time by Server Side code
- Webserver is not configured [...]]]></description>
			<content:encoded><![CDATA[<p>In the last couple of hours I was contemplating around maintainable, performant and non-obstrusive Javascript on a project I am working on.</p>
<p><strong>Following situation:</strong><br />
- Much Inline Javascript<br />
- Many JS and CSS files referenced<br />
- No Frontend Deployment/Build Process in place<br />
- Some Javascript values are set at page generation time by Server Side code<br />
- Webserver is not configured yet correctly for setting expires &amp; compression headers</p>
<p><strong>Problems with this:</strong><br />
- Maintainability and separation of concerns is an issue with lots of inline JS<br />
- Long Pageload because of many HTTP request<br />
- Webserver takes big hit for all the static content loading<br />
- Network is being stressed as well<br />
- Javascript Logic is unobfuscated/not minimised and visible to the world</p>
<p><strong>Tasks:</strong></p>
<ul>
<li>Externalize JS</li>
<li>Modularisation of JS Dependency Loading vs. all in one</li>
<li>Configuration of HTTP headers in Webserver</li>
<li>Identify Scripts / static content for CDN</li>
<li>Seamless Deployment/Build process from comfortable JS dev to the production code</li>
</ul>
<p>The &#8220;challenge&#8221; was to externalise the inline Javascript.</p>
<p>For modularisation there are <a href="http://getsprockets.org" target="_blank">several</a> <a href="http://www.nczonline.net/blog/2009/09/22/introducing-combiner-a-javascriptcss-concatenation-tool/" target="_blank">tools </a>to handle the dependency combination of Javascript files. Depending on the amount of Javascript and the usage metrics  you can as well just pack all in one. Of course there are <a href="http://www.hunlock.com/blogs/Supercharged_Javascript" target="_blank">many</a> <a href="http://carsonified.com/blog/features/webapps/serving-javascript-fast/" target="_blank">other</a> methods for combination and modularisation and you can as well just run your own method. So this is bascially just a matter of choosing the right tool / method and not that difficult. For compressing / minimisation the <a href="http://developer.yahoo.com/yui/compressor">YUI compressor</a> seems like state of the art.</p>
<p>Configuration of the correct headers is also just a &#8211; well &#8211; configuration task of setting meanigful caching control and expires headers and deflate compression for Apache2, so that the documents get compressed over the network. As for deploment and build process sprockets, ant or others are a valiable solution.</p>
<p>What I would like to share here is the solution for externalize Javascript that was initialised by server side code.</p>
<p>The basic idea builds upon<a href="http://www.dustindiaz.com/namespace-your-javascript/" target="_blank"> this post</a> by dustin diaz. So I am not gonna repeat his content instead if you are not familiar with private, public and privileged Objects in Javascript you might read his post first. As a starting point when combining multiple inline Javascript files we have to take care about namespaces.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//just namespacing</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> registerNS<span style="color: #009900;">&#40;</span>ns<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 <span style="color: #003366; font-weight: bold;">var</span> nsParts <span style="color: #339933;">=</span> ns.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #003366; font-weight: bold;">var</span> root <span style="color: #339933;">=</span> window<span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i</pre></div></div>

<p>Ok so far so good, now we need to have a way initialise those external Javascript files with dynamic server-side variables:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//initialise a namespaced object</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> MY <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: #003366; font-weight: bold;">var</span> private_var<span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">function</span> private_method<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// do stuff here</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
                init <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>var1<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    private_var<span style="color: #339933;">=</span>var1<span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		method_1 <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;">&quot;method 1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		method_2 <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>private_var<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: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
MY.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;hey you!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
MY.<span style="color: #660066;">method_1</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
MY.<span style="color: #660066;">method_2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That worked out as well. But there&#8217;s a but. Our javascript will be referenced externally and along with the <a href="http://developer.yahoo.com/performance/rules.html#external" target="_blank">YUI Performance rules</a> the script include tags will be at the bottom of the page. The initialisation code on the other hand is at the top of every page fragment/widget and might be executed at rendering time. To prevent timing problems the initialisation code therfore needs to configure an object that is already live:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//global js config obj</span>
<span style="color: #003366; font-weight: bold;">var</span> runcfg <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//within html</span>
<span style="color: #003366; font-weight: bold;">var</span> a <span style="color: #339933;">=</span> runcfg<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;details&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
a<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;url&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://uebersoftware.com&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//external js</span>
<span style="color: #003366; font-weight: bold;">var</span> MY <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: #003366; font-weight: bold;">var</span> private_var<span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> myconfig <span style="color: #339933;">=</span> runcfg<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;details&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">function</span> private_method<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// do stuff here</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
                init <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>var1<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    private_var<span style="color: #339933;">=</span>var1<span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		method_1 <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>myconfig <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;url&quot;</span><span style="color: #009900;">&#93;</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: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// usage</span>
MY.<span style="color: #660066;">method_1</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This method allows us easy externalized the Javascript without much refactoring. The script code is namespaced and is still dynamically configurable.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.uebersoftware.com/2009/10/initialise-external-javascript-in-page-fragments/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>FB Series: Integrating JS</title>
		<link>http://www.uebersoftware.com/2009/07/fb-series-integrating-js/</link>
		<comments>http://www.uebersoftware.com/2009/07/fb-series-integrating-js/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 15:03:00 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[facebook]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.uebersoftware.com/2009/07/fb-series-integrating-js/</guid>
		<description><![CDATA[Where are we coming from 
Javascript one of the most popular language for web programming. Although it has been around for decades, &#8211; coming from Netscape 1995 &#8211; it was not until the advent of the Ajax and Web 2.0 when JavaScript came to the spotlight and brought more professional programming attention.
The OpenSource movement of [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: rgb(32, 18, 77);font-size:130%;" ><br /><span style="font-weight: bold;">Where are we coming from </span></span></p>
<p>Javascript one of the most popular language for web programming. Although it has been around for decades, &#8211; coming from Netscape 1995 &#8211; it was not until the advent of the Ajax and Web 2.0 when JavaScript came to the spotlight and brought more professional programming attention.</p>
<p>The OpenSource movement of JavaScript frameworks started in 2005 with prototype and script.aculo.us. Since then programming appealing JavaScript based Websites has become so much easier. Nowadays its litteraly possible to mash-up widgets with little to no JavaScript knowledge and set up a stunning page. I would however still recommend for someone not knowing JavaScript first to get the basics and maybe have some <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference">JS Reference</a> &amp; <a href="https://developer.mozilla.org/en/Gecko_DOM_Reference">DOM Reference</a> handy.</p>
<p>Looking at the core functionality of todays frameworks what do we have?
<ul>
<li>DOM Traversal with CSS selectors to locate elements</li>
<li>DOM Modification: Create/remove/modify elements</li>
<li>Short syntax for adding/removing Events</li>
<li>Short syntax for Ajax Request</li>
<li>Animations (hide/show/toggle) &amp; Transition</li>
<li>User Interface Widgets (Drag &amp; drop, Tree, Grid, Datepicker, Model Dialog, Menu / Toolbar, Slider, Tabbed Pane)</li>
<li>Wide Browser Support</li>
</ul>
<p>
<div style="background-color: white; color: rgb(7, 55, 99); font-weight: bold;"><span style="font-size:130%;">Choosing a JS Framework</span></div>
<p>On the net you will find a mirrad of comparisons of popular frameworks. The most popular OpenSource  and free JS Frameworks available today are:</p>
<p>  * Prototype (&amp;Scriptaculous  for UI)<br />  * Dojo<br />  * jQuery<br />  * YUI<br />  * Mootools</p>
<p>I would say that all of those have their advantages and drawbacks and there&#8217;s not really an obvious winner. It really depends on what you use it for. Some helpful links that helped me choosing are:</p>
<p><a href="http://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks">Wikipedia</a> &#8211; to get a feeling on the features<br /><a href="http://ajax.wikispaces.com/functional_comparison">unbiased functional comparison</a><br /><a href="http://goog_1247925525350/">Stackoverflow</a> comparing JQuery Dojo and more<br /><a href="http://blog.creonfx.com/javascript/mootools-vs-jquery-vs-prototype-vs-yui-vs-dojo-comparison-revised">Performance comparison</a></p>
<p>Choosing a framework, as mentioned, depends a bit on how you want to use JavaScript:</p>
<p><b>Plug-and-Play:</b>
<ul>
<li>Drop in a “calendar widget” or “tabbed navigation”</li>
<li>Little, to no, JavaScript experience required.</li>
<li>Just customize some options and go.</li>
<li>No flexibility.</li>
</ul>
<p>=&gt; Widgets</p>
<p><b>Some Assembly Required</b>
<ul>
<li>Write common utilities</li>
<li>Click a link, load a page via Ajax</li>
<li>Build a dynamic menu</li>
<li>Creating interactive forms</li>
<li>Use pre-made code to distance yourself from browser bugs.</li>
<li>Flexible, until you hit a browser bug.</li>
</ul>
<p>=&gt; Libraries</p>
<p><b>Down-and-Dirty</b>
<ul>
<li>Write all JavaScript code from scratch</li>
<li>Deal, directly, with browser bugs</li>
<li>Quirksmode is your lifeline</li>
<li>Excessively flexible, to the point of hinderance.</li>
</ul>
<p>=&gt; Raw Java Script</p>
<p>Of course you can also mix different approaches, as you can also mix Frameworks but of course in terms of maintainability and productivity it would better if you don&#8217;t have to.</p>
<p>For my personal use case I had the following requirements:
<ol>
<li>Easy to learn with minimal intuitive syntax</li>
<li>Lightweight solution</li>
<li>Availability of some widgets: Datepicker, Grid, maybe more</li>
<li>Appealing Web 2.0 effects</li>
<li>Production quality</li>
</ol>
<p>Right now I have choosen <a href="http://jquery.com/">jQuery</a> (incl. <a href="http://jqueryui.com/">jQuery UI</a>) and see how far I get with it. It was to me the most appealing in terms of the above criterias. I am not sure if I need a sophisticated data table, if so I might have another look at YUI data table which seems to me one of the <a href="http://yuiblog.com/blog/2008/10/15/datatable-260-part-one/">best widgets</a> for this (compare to e.g. <a href="http://www.datatables.net/">this</a> jQuery plugin).</p>
<p>For development i guess its essential to still have a good Javascript support in your IDE and a JavaScript debugger &#8211; I use Firebug and Netbeans for this. If you are into Eclipse I strongly suggest to take a look at <a href="http://www.aptana.com/">Aptana</a>, their IDE is really great for JavaScript and PHP, but unfortunately not optimal for Facebook development.</p>
<p>As a last hint: consider using Google <a href="http://code.google.com/apis/ajaxlibs/">Ajax Libs</a> for speed up JS loading on your clients. However do not use it in local development. It just does not work reliable (loads too late etc.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.uebersoftware.com/2009/07/fb-series-integrating-js/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
