<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:series="http://unfoldingneurons.com/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en" xml:base="http://davidwalsh.name/wp-atom.php"><title type="text">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</title> <subtitle type="text">Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</subtitle><updated>2012-04-29T03:52:17Z</updated><link rel="alternate" type="text/html" href="http://davidwalsh.name" /> <id>http://davidwalsh.name/feed/atom</id><generator uri="http://wordpress.org/" version="3.3.2">WordPress</generator> <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/Bludice" /><feedburner:info uri="bludice" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><geo:lat>43.072994</geo:lat><geo:long>-89.519924</geo:long><feedburner:emailServiceId>Bludice</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[Squash Commits with&#160;Git]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/IvjXI1BJoJQ/squash-commits-git" /> <id>http://davidwalsh.name/?p=5422</id> <updated>2012-04-29T03:52:17Z</updated> <published>2012-04-29T03:52:17Z</published> <category scheme="http://davidwalsh.name" term="Shell" /> <summary type="html"><![CDATA[I&#8217;m not a git expert but I know enough git to get by, and surely know enough git to appreciate its ease of use over svn. A while ago I published some basic git commands to that go slightly beyond basic cloning and commits, and should handle most git interactions. Today&#8217;s mini git lesson involves [...]<p><a
href="http://davidwalsh.name/squash-commits-git">Squash Commits with&nbsp;Git</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></summary> <content type="html" xml:base="http://davidwalsh.name/squash-commits-git">&lt;p&gt;I&amp;#8217;m not a git expert but I know enough git to get by, and surely know enough git to appreciate its ease of use over svn.  A while ago I published some &lt;a
href="http://davidwalsh.name/git-commands"&gt;basic git commands&lt;/a&gt; to that go slightly beyond basic cloning and commits, and should handle most git interactions.  Today&amp;#8217;s mini git lesson involves squashing multiple commits into one, allowing for easier pull request review and merge management.&lt;/p&gt;&lt;p&gt;Start by making changes to the feature branch you&amp;#8217;re doing work on.  Let&amp;#8217;s assume that these changes span a few commits and I want to consolidate them into one commit.  The first step involves making sure the master branch is up to date with the destination repo&amp;#8217;s master branch:&lt;/p&gt;&lt;pre class="shell"&gt;
# switch to master branch
git checkout master

# ensure our master is up to date
git pull remoteRepoName master
&lt;/pre&gt;&lt;p&gt;With the master branch up to date, we&amp;#8217;ll use git rebase to consolidate:&lt;/p&gt;&lt;pre class="shell"&gt;
git rebase -i master
&lt;/pre&gt;&lt;p&gt;That command will show a list of each commit, as such:&lt;/p&gt;&lt;pre class="shell"&gt;
pick fb554f5 This is commit 1
pick 2bd1903 This is commit 2
pick d987ebf This is commit 3

# Rebase 9cbc329..d987ebf onto 9cbc329
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
&lt;/pre&gt;&lt;p&gt;Edit the summary shown to you by the rebase command, leaving the commit you want to be the main commit as &amp;#8220;pick&amp;#8221; and changing all subsequent &amp;#8220;pick&amp;#8221; commands as &amp;#8220;squash&amp;#8221;:&lt;/p&gt;&lt;pre class="shell"&gt;
pick fb554f5 This is commit 1
squash 2bd1903 This is commit 2
squash d987ebf This is commit 3

# Rebase 9cbc329..d987ebf onto 9cbc329
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
&lt;/pre&gt;&lt;p&gt;Write/quit past the editor twice (the second screen would allow you to change the commit message, though I like to keep it the same).  At this point, your commits are squashed into one.  Run the following command to force a push of the new, consolidated commit:&lt;/p&gt;&lt;pre class="shell"&gt;
git push -f
&lt;/pre&gt;&lt;p&gt;This forced push updates the source repository and our commits have become one.  If you had already submitted a pull request at GitHub, the pull request would now show only one commit!  With one consolidated commit, code review becomes much, much easier!&lt;/p&gt;&lt;p&gt;&lt;a
href="http://davidwalsh.name/squash-commits-git"&gt;Squash Commits with&amp;nbsp;Git&lt;/a&gt; is a post from: &lt;a
href="http://davidwalsh.name"&gt;David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.&lt;/a&gt;&lt;/p&gt; &lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/IvjXI1BJoJQ" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/squash-commits-git#comments" thr:count="0" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/squash-commits-git/feed/atom" thr:count="0" /> <thr:total>0</thr:total> <feedburner:origLink>http://davidwalsh.name/squash-commits-git</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[Thoughts on &#8220;Silent&#8221; Browser&#160;Upgrades]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/eBbVsM9ZU-k/silent-browser-upgrades" /> <id>http://davidwalsh.name/?p=5420</id> <updated>2012-04-28T16:25:27Z</updated> <published>2012-04-27T03:14:11Z</published> <category scheme="http://davidwalsh.name" term="Browsers" /> <summary type="html"><![CDATA[With the release of version 12, Mozilla Firefox joins the Google Chrome ranks of silent browser updates.  This topic has gotten a lot of attention over the past few days due to Firefox&#8217;s release and the fact that Mozilla the second vendor to implement said feature.  Microsoft has said they plan to implement silent updates [...]<p><a
href="http://davidwalsh.name/silent-browser-upgrades">Thoughts on &#8220;Silent&#8221; Browser&nbsp;Upgrades</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></summary> <content type="html" xml:base="http://davidwalsh.name/silent-browser-upgrades">&lt;p&gt;With the release of version 12, Mozilla Firefox joins the Google Chrome ranks of silent browser updates.  This topic has gotten a lot of attention over the past few days due to Firefox&amp;#8217;s release and the fact that Mozilla the second vendor to implement said feature.  Microsoft has said they plan to implement silent updates as well.  I contend that automatic browser upgrading is a good practice.  Let me share my reasons for such, and propose a few ideas for improvement.&lt;p&gt;&lt;p&gt;&lt;em&gt;Full disclosure:  I&amp;#8217;m a Mozilla employee.  That has no bearing on my opinion, however.&lt;/em&gt;&lt;/p&gt;&lt;h2&gt;See Past Your&amp;nbsp;Expertise&lt;/h2&gt;&lt;p&gt;One thing many developers overlook is their own technical expertise.  It&amp;#8217;s sobering to me that none of my personal friends know what I do, much less name more than two browsers.  Realize that 99% of web users don&amp;#8217;t care which browser they&amp;#8217;re using &amp;#8212; they just expect websites to work.  My mother, my grandmother, my uncle don&amp;#8217;t know what &amp;#8220;browser&amp;#8221; means or which one they use;  they simply know that clicking the blue &amp;#8220;e&amp;#8221; opens the internet.  If they don&amp;#8217;t know what browser they use, what are the chances they know how to upgrade their browser, or choose a better vendor?  They don&amp;#8217;t.  Should the expect a great experience from our web applications?  Of course.  Silent browser upgrading solves the issue of helping those that can&amp;#8217;t help themselves.&lt;/p&gt;&lt;h2&gt;The Internet Explorer&amp;nbsp;Example&lt;/h2&gt;&lt;p&gt;The most obvious example of why automatic browser updating is important is Internet Explorer.  Think of how many &lt;em&gt;years&lt;/em&gt; we&amp;#8217;ve bitched about Internet Explorer 6.  Of course the true issue with IE6 is that Microsoft neglected the browser market, but when Microsoft resumed their commitment to IE, pushing IE6 users to a newer version proved all but impossible.  IE6 is &lt;em&gt;still a consideration today.  &lt;/em&gt;Silent browser upgrades would have allowed IE to push browser upgrades and bypass the years of frustration we&amp;#8217;ve gone through.&lt;/p&gt;&lt;h2&gt;UA Sniffs Gone; Feature Detection&amp;nbsp;Here&lt;/h2&gt;&lt;p&gt;When the web and browsers were simpler, there were less features to detect and thus developers didn&amp;#8217;t give thought to feature detection, so much as simple user agent sniffing.  We&amp;#8217;re smarter now and there are better tools to allow us to detect what we need.  Of course there will always be developers who don&amp;#8217;t follow best practice, but with the proper techniques in place and known, sniffing (and thus browser version) is becoming less of an issue.&lt;/p&gt;&lt;h2&gt;Updates are Still&amp;nbsp;Optional&lt;/h2&gt;&lt;p&gt;Firefox allows the web-conscious user to stop automatic updates;  silent updating is simply the default.  One thing we need to realize is that since we&amp;#8217;re the experts, we need to find a way to get browsers of a specific version;  it shouldn&amp;#8217;t be the user&amp;#8217;s responsibility to ensure upgrades;  see the reasons above to know why.  Users who don&amp;#8217;t know or care about updates wouldn&amp;#8217;t touch this setting and thus only knowledgeable persons would be effected.&lt;/p&gt;&lt;h2&gt;Improvement&lt;/h2&gt;&lt;p&gt;There&amp;#8217;s always room for improvement for us.  And by &amp;#8220;us&amp;#8221;, I mean &amp;#8220;developers&amp;#8221;, as we&amp;#8217;re the true connoisseurs of browsers.  We must have each browser version accessible to us by the vendor, and we should be provided the ability to prevent browser version upgrades.  Mozilla provides each version on their FTP site, and &lt;a
href="https://github.com/omgmog/install-all-firefox"&gt;this script&lt;/a&gt; allows for Firefox installation of all versions without upgrade abilities;  an incredible script.  Browsers vendors also need a bulletproof strategy for ensuring popular extensions work with each browser upgrade, allowing users with little knowledge (just enough to get an extension installed).&lt;p&gt;&lt;h2&gt;In&amp;nbsp;Short&amp;#8230;&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;Get over yourself: not everyone cares about what browser they use&lt;/li&gt;&lt;li&gt;Some don&amp;#8217;t know what a browser is; they just want stuff to work&lt;/li&gt;&lt;li&gt;Be a better developer&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;This is where you can tell me I&amp;#8217;m wrong.  Bring it.&lt;/p&gt;&lt;p&gt;&lt;a
href="http://davidwalsh.name/silent-browser-upgrades"&gt;Thoughts on &amp;#8220;Silent&amp;#8221; Browser&amp;nbsp;Upgrades&lt;/a&gt; is a post from: &lt;a
href="http://davidwalsh.name"&gt;David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.&lt;/a&gt;&lt;/p&gt; &lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/eBbVsM9ZU-k" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/silent-browser-upgrades#comments" thr:count="11" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/silent-browser-upgrades/feed/atom" thr:count="11" /> <thr:total>11</thr:total> <feedburner:origLink>http://davidwalsh.name/silent-browser-upgrades</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[OSX Lion Dock&#160;Dividers]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/PCHkxBAWjDY/osx-lion-dock-dividers" /> <id>http://davidwalsh.name/?p=5418</id> <updated>2012-04-20T22:37:09Z</updated> <published>2012-04-20T22:37:09Z</published> <category scheme="http://davidwalsh.name" term="Shell" /> <summary type="html"><![CDATA[One thing I hate is Tottenham Football Club clutter.  I hate cluttered code, files littered on the desktop, and keeping files in my Downloads folder that I&#8217;ll never need again.  One place I especially hate clutter is my OSX application dock.  I recently upgraded to OSX Lion and found that my old divider apps, which I [...]<p><a
href="http://davidwalsh.name/osx-lion-dock-dividers">OSX Lion Dock&nbsp;Dividers</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></summary> <content type="html" xml:base="http://davidwalsh.name/osx-lion-dock-dividers">&lt;p&gt;One thing I hate is &lt;del&gt;Tottenham Football Club&lt;/del&gt; clutter.  I hate cluttered code, files littered on the desktop, and keeping files in my Downloads folder that I&amp;#8217;ll never need again.  One place I &lt;em&gt;especially&lt;/em&gt; hate clutter is my OSX application dock.  I recently upgraded to OSX Lion and found that my old divider apps, which I used to separate related dock apps, were no longer acceptable.  As you can imagine, I wasn&amp;#8217;t impressed.  Luckily I found a great way to create dividers on &lt;em&gt;both&lt;/em&gt; sides of the dock with minimal fuss and without the need for phantom apps!&lt;/p&gt;&lt;h2&gt;Step 1:  Create the&amp;nbsp;Dividers&lt;/h2&gt;&lt;p&gt;Open the Terminal and execute the first command to create a divider on the left or the second comment to add one on the right:&lt;/p&gt;&lt;pre class="shell"&gt;
# Left side
defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'

# Right Side
defaults write com.apple.dock persistent-others -array-add '{tile-data={}; tile-type="spacer-tile";}'
&lt;/pre&gt;&lt;p&gt;Execute the command as many times as you like; a divider will be created each time.  You will not, however, see them added before your eyes.&lt;/p&gt;&lt;h2&gt;Step 2:  Reset the&amp;nbsp;Dock&lt;/h2&gt;&lt;p&gt;Reset the dock to see your new divider(s):&lt;/p&gt;&lt;pre class="shell"&gt;
# Reset the dock
killall Dock
&lt;/pre&gt;&lt;p&gt;Once the dock is reset, you&amp;#8217;ll see spacers which you&amp;#8217;ll be able to drag throughout the dock.&lt;/p&gt;&lt;p&gt;Why dividers aren&amp;#8217;t a common feature of OSX yet is a question I can&amp;#8217;t answer.  Luckily we can abuse Terminal to make our dividers though.&lt;/p&gt;&lt;p&gt;&lt;a
href="http://davidwalsh.name/osx-lion-dock-dividers"&gt;OSX Lion Dock&amp;nbsp;Dividers&lt;/a&gt; is a post from: &lt;a
href="http://davidwalsh.name"&gt;David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.&lt;/a&gt;&lt;/p&gt; &lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/PCHkxBAWjDY" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/osx-lion-dock-dividers#comments" thr:count="1" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/osx-lion-dock-dividers/feed/atom" thr:count="1" /> <thr:total>1</thr:total> <feedburner:origLink>http://davidwalsh.name/osx-lion-dock-dividers</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[DNS&#160;Prefetching]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/bFNY9l-bw78/dns-prefetching" /> <id>http://davidwalsh.name/?p=5415</id> <updated>2012-04-17T21:55:38Z</updated> <published>2012-04-17T21:55:38Z</published> <category scheme="http://davidwalsh.name" term="Markup" /> <summary type="html"><![CDATA[Despite anchor tags having HREF attributes which lead to other host names, browsers do not execute DNS lookups on those domains. Content prefetching can be invaluable in speeding up your websites, but did you know that you can also implement DNS prefetching? It&#8217;s as easy as simple LINK element: This technique can be very useful [...]<p><a
href="http://davidwalsh.name/dns-prefetching">DNS&nbsp;Prefetching</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></summary> <content type="html" xml:base="http://davidwalsh.name/dns-prefetching">&lt;p&gt;Despite anchor tags having &lt;code&gt;HREF&lt;/code&gt; attributes which lead to other host names, browsers do not execute DNS lookups on those domains. Content prefetching can be invaluable in speeding up your websites, but did you know that you can also implement DNS prefetching?  It&amp;#8217;s as easy as simple &lt;code&gt;LINK&lt;/code&gt; element:&lt;/p&gt;&lt;pre class="html"&gt;
&lt;link rel="dns-prefetch" href="//somehost.tld" /&gt;
&lt;/pre&gt;&lt;p&gt;This technique can be very useful when your website links to related host names.  Take Twitter for example;  they implement two DNS prefetches:&lt;/p&gt;&lt;pre class="html"&gt;
&lt;link rel="dns-prefetch" href="https://si0.twimg.com" /&gt;
&lt;link rel="dns-prefetch" href="https://api.twitter.com" /&gt;
&lt;/pre&gt;&lt;p&gt;I&amp;#8217;d be willing to bet that most of you didn&amp;#8217;t know this tag existed.  It&amp;#8217;s an interesting idea with a very simple execution.  What do you think?  Do you manage websites that prefetching could be helpful for?&lt;/p&gt;&lt;p&gt;&lt;a
href="http://davidwalsh.name/dns-prefetching"&gt;DNS&amp;nbsp;Prefetching&lt;/a&gt; is a post from: &lt;a
href="http://davidwalsh.name"&gt;David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.&lt;/a&gt;&lt;/p&gt; &lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/bFNY9l-bw78" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/dns-prefetching#comments" thr:count="1" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/dns-prefetching/feed/atom" thr:count="1" /> <thr:total>1</thr:total> <feedburner:origLink>http://davidwalsh.name/dns-prefetching</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[CSS Animations Between Media&#160;Queries]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/ZWurlEvXyjE/animate-media-queries" /> <id>http://davidwalsh.name/?p=5412</id> <updated>2012-04-12T18:53:18Z</updated> <published>2012-04-10T23:03:28Z</published> <category scheme="http://davidwalsh.name" term="CSS" /><category scheme="http://davidwalsh.name" term="Mobile" /> <summary type="html"><![CDATA[CSS animations are right up there with sliced bread. CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very CSS little code. Quite often we add CSS transforms to elements via CSS during :hover, and we also create keyframe-based animations by adding a className, [...]<p><a
href="http://davidwalsh.name/animate-media-queries">CSS Animations Between Media&nbsp;Queries</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></summary> <content type="html" xml:base="http://davidwalsh.name/animate-media-queries">&lt;p&gt;CSS animations are right up there with sliced bread.  CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very CSS little code.  Quite often we add CSS transforms to elements via CSS during :hover, and we also create keyframe-based animations by adding a className, but did you know you can animate elements using media queries as the trigger?  Let&amp;#8217;s have a look!&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/animate-media-queries.php" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;The&amp;nbsp;CSS&lt;/h2&gt;&lt;p&gt;The syntax for creating these animations and transitions is the same between media queries as it is between element states;  the only difference is actually enacting them between the media queries:&lt;/p&gt;&lt;pre class="css"&gt;
/* base state */
#layout { 
	position: relative; 
	width: 900px; 
	border: 1px solid #ccc; 
	height: 200px; 
	
	/* animate width over a given duration */
	-webkit-transition: width 2s;
	-moz-transition: width 2s;
	-ms-transition: width 2s;
}
.child {
	top: 0; 
	bottom: 0;
	width: 290px;
	position: absolute;
	opacity: 1;
	font-size: 20px;
	overflow: hidden;
	-webkit-transform: translate3d(0, 0, 0);
	
	/* animate opacity, left, width over a given duration */
	-webkit-transition: opacity 2s, width 2s, left 2s, font-size 2s, color 2s;
	-moz-transition: opacity 2s, width 2s, left 2s, font-size 2s, color 2s;
	-ms-transition: opacity 2s, width 2s, left 2s, font-size 2s, color 2s;
}
	#child1 { left: 0; background: lightblue; }
	#child2 { left: 300px; background: lightgreen; }
	#child3 { left: 600px; background: lightyellow; }

/* 
	When the client has 860 width or less:
	 	- animate the first two elements to be wider
		- fade out and hide the third element
		- animate the background colors
		- animate the font-size of the block
*/
@media screen and (max-width: 860px) {
	#layout { width: 600px; }
	.child { width: 290px; font-size: 12px; }
	#child1 { left: 0; background: blue; color: #fff; }
	#child2 { left: 300px; background: green; color: #fff; }
	#child3.child { /* hider */ opacity: 0; width: 0; }
}
&lt;/pre&gt;&lt;p&gt;The creativity is all in the developer&amp;#8217;s hands; animating media queries isn&amp;#8217;t difficult, but the use of them is more interesting.  Some sites used to animate the position of structure elements during window resize, which is nice but how often is that a realistic usage?  A more realistic usage is with mobile devices, animating elements when orientation changes:&lt;/p&gt;&lt;pre class="css"&gt;
/* base mobile styles */
#sidebar {
	-webkit-transition: opacity 2s;
	width: 300px;
	overflow: hidden;
}

/* portrait */
@media screen and (orientation:portrait) { 
	/* portrait-specific styles */ 
	#sidebar {
		opacity: 0;
		width: 0;
	}
}

/* landscape */
@media screen and (orientation:landscape) {
	/* landscape-specific styles */
	#sidebar {
		opacity: 1;
	}
}
&lt;/pre&gt;&lt;p&gt;The animation above triggers when the device goes from portrait to landscape, and visa versa.  This is incredibly useful when hiding a pane in portrait view and elegantly showing that pane when the user switches to landscape view.&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/animate-media-queries.php" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;CSS animations between media queries have traditionally been a delicacy of web design, but there &lt;em&gt;are&lt;/em&gt; practical uses.  The best part of them?  There is no JavaScript involved and you can force &lt;a
href="http://davidwalsh.name/translate3d"&gt;CSS hardware acceleration&lt;/a&gt; if you&amp;#8217;d like.  Take a few moments to look at your mobile site to see if you can add this effect.&lt;/p&gt;&lt;p&gt;&lt;a
href="http://davidwalsh.name/animate-media-queries"&gt;CSS Animations Between Media&amp;nbsp;Queries&lt;/a&gt; is a post from: &lt;a
href="http://davidwalsh.name"&gt;David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.&lt;/a&gt;&lt;/p&gt; &lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/ZWurlEvXyjE" height="1" width="1"/&gt;</content> <series:name scheme="http://davidwalsh.name" term="CSS3 Animations" /><link rel="replies" type="text/html" href="http://davidwalsh.name/animate-media-queries#comments" thr:count="4" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/animate-media-queries/feed/atom" thr:count="4" /> <thr:total>4</thr:total> <feedburner:origLink>http://davidwalsh.name/animate-media-queries</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[Multiple Backgrounds with&#160;CSS]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/8ktCHtvbOmE/css-multiple-background" /> <id>http://davidwalsh.name/?p=5411</id> <updated>2012-04-04T01:43:05Z</updated> <published>2012-04-04T01:43:05Z</published> <category scheme="http://davidwalsh.name" term="CSS" /> <summary type="html"><![CDATA[Anyone that&#8217;s been in the web development industry for 5+ years knows that there are certain features that we should have had several years ago. One of those features is the HTML5 placeholder; we used JavaScript shims for a decade before placeholder came along. Another one of those simple features is multiple background images with [...]<p><a
href="http://davidwalsh.name/css-multiple-background">Multiple Backgrounds with&nbsp;CSS</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></summary> <content type="html" xml:base="http://davidwalsh.name/css-multiple-background">&lt;p&gt;Anyone that&amp;#8217;s been in the web development industry for 5+ years knows that there are certain features that we should have had several years ago.  One of those features is the &lt;a
href="http://davidwalsh.name/html5-placeholder"&gt;HTML5 placeholder&lt;/a&gt;;  we used JavaScript shims for a decade before placeholder came along.  Another one of those simple features is multiple background images with CSS.  Instead we&amp;#8217;d need to nest another element for every additional background image.  Now we a syntax for supporting multiple background images on one element, and here&amp;#8217;s what it looks like.&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/css-multiple-background.php" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;The&amp;nbsp;CSS&lt;/h2&gt;&lt;p&gt;Multiple backgrounds involved using multiple property assignments with multiple values, separated by a comma:&lt;/p&gt;&lt;pre class="css"&gt;
#multipleBGs {
	background: url(photo1.png),
				url(photo2.png),
				url(photo3.png)
	;
	background-repeat: no-repeat,
					   no-repeat,
					   repeat-y;
						
	background-position: 0 0,
						 30px 70px,
						 right top;
	
	width: 400px; 
	height: 400px;
	border: 1px solid #ccc;
}
&lt;/pre&gt;&lt;p&gt;Trying to stuff all properties via shorthand within the background property wont work, unfortunately; multiple property declarations must be used.  All of the background properties may be used (background-attachment , background-clip , background-image , background-origin , background-position , background-repeat , background-size), as well as CSS gradients.&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="http://davidwalsh.name/dw-content/css-multiple-background.php" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Another awesome CSS feature that we can finally used.  Using multiple CSS backgrounds is an incredible useful tool, preventing the need for nested elements for the sole purpose of formatting.&lt;/p&gt;&lt;p&gt;&lt;a
href="http://davidwalsh.name/css-multiple-background"&gt;Multiple Backgrounds with&amp;nbsp;CSS&lt;/a&gt; is a post from: &lt;a
href="http://davidwalsh.name"&gt;David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.&lt;/a&gt;&lt;/p&gt; &lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/8ktCHtvbOmE" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/css-multiple-background#comments" thr:count="6" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/css-multiple-background/feed/atom" thr:count="6" /> <thr:total>6</thr:total> <feedburner:origLink>http://davidwalsh.name/css-multiple-background</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[JavaScript CSS&#160;Helpers]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/638L6N8YY-U/javascript-css" /> <id>http://davidwalsh.name/?p=5410</id> <updated>2012-04-04T00:12:44Z</updated> <published>2012-04-04T00:12:44Z</published> <category scheme="http://davidwalsh.name" term="CSS" /><category scheme="http://davidwalsh.name" term="JavaScript" /> <summary type="html"><![CDATA[I spend a good amount of time looking at JavaScript framework source code. Regardless of which frameworks you have allegiance to, you can learn an awful lot by looking under the hood of widely used code collections. One of many handy snippets can be found within the MooTools source code: functions to camelize and hyphenate [...]<p><a
href="http://davidwalsh.name/javascript-css">JavaScript CSS&nbsp;Helpers</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></summary> <content type="html" xml:base="http://davidwalsh.name/javascript-css">&lt;p&gt;I spend a good amount of time looking at JavaScript framework source code.  Regardless of which frameworks you have allegiance to, you can learn an awful lot by looking under the hood of widely used code collections.  One of many handy snippets can be found within the MooTools source code:  functions to camelize and hyphenate strings so that your own min framework can accept either form of CSS setter or getter.  Here are the functions in all of their glory.&lt;/p&gt;&lt;h2&gt;The&amp;nbsp;JavaScript&lt;/h2&gt;&lt;p&gt;As you could probably guess, this task is best accomplished with regular expressions:&lt;/p&gt;&lt;pre class="js"&gt;
function camelize(str) {
	return (str + "").replace(/-\D/g, function(match) {
		return match.charAt(1).toUpperCase();
	});
}
camelize("border-bottom-color"); // "borderBottomColor"


function hyphenate(str) {
	return (str + "").replace(/[A-Z]/g, function(match) {
		return "-" + match.toLowerCase();
	});
}
hyphenate("borderBottomColor"); // "border-bottom-color"
&lt;/pre&gt;&lt;p&gt;A couple of really handy JavaScript String to corresponding String format functions.  Instead of expecting strings in only one format, your mini library can now accept both!&lt;/p&gt;&lt;p&gt;&lt;a
href="http://davidwalsh.name/javascript-css"&gt;JavaScript CSS&amp;nbsp;Helpers&lt;/a&gt; is a post from: &lt;a
href="http://davidwalsh.name"&gt;David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.&lt;/a&gt;&lt;/p&gt; &lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/638L6N8YY-U" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/javascript-css#comments" thr:count="0" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/javascript-css/feed/atom" thr:count="0" /> <thr:total>0</thr:total> <feedburner:origLink>http://davidwalsh.name/javascript-css</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[View Browser Repaints in Google Chrome and Mozilla&#160;Firefox]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/U-1VmT48FVo/browser-repaint" /> <id>http://davidwalsh.name/?p=5406</id> <updated>2012-04-21T12:38:41Z</updated> <published>2012-03-29T04:21:03Z</published> <category scheme="http://davidwalsh.name" term="Browsers" /><category scheme="http://davidwalsh.name" term="CSS" /> <summary type="html"><![CDATA[One goal of super-optimized websites is to prevent browser repaints due to changes in a block&#8217;s style or content. There are numerous ways we intentionally (or unintentionally) trigger block repaints, but the browser does it so quickly we have trouble seeing when and where it happens. Recognizing the importance of allowing developers to micro-optimize their [...]<p><a
href="http://davidwalsh.name/browser-repaint">View Browser Repaints in Google Chrome and Mozilla&nbsp;Firefox</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></summary> <content type="html" xml:base="http://davidwalsh.name/browser-repaint">&lt;p&gt;One goal of super-optimized websites is to prevent browser repaints due to changes in a block&amp;#8217;s style or content.  There are numerous ways we intentionally (or unintentionally) trigger block repaints, but the browser does it so quickly we have trouble seeing when and where it happens.  Recognizing the importance of allowing developers to micro-optimize their pages, the Chrome and Firefox teams have added features to their browsers to allow us to see those repaints.  Here&amp;#8217;s how to do it!&lt;/p&gt;&lt;h2&gt;Google Chrome &amp;amp;&amp;nbsp;Canary&lt;/h2&gt;&lt;p&gt;The repaint feature needs to be enabled at startup for Chrome and Canary with the &lt;code&gt;--show-paint-rects&lt;/code&gt; config:&lt;/p&gt;&lt;pre class="shell"&gt;
open ./Google\ Chrome\ Canary.app --args --show-paint-rects
&lt;/pre&gt;&lt;p&gt;Be sure to include &lt;code&gt;--args&lt;/code&gt; in your command or you&amp;#8217;ll run into problems opening the browser.  Repaints will display on each site you visit.&lt;/p&gt;&lt;h2&gt;Mozilla Firefox, Aurora,&amp;nbsp;Nightly&lt;/h2&gt;&lt;p&gt;To view repaints in Firefox and Aurora browsers, you need to enable an about:config option.  The option name is &lt;code&gt;nglayout.debug.paint_flashing&lt;/code&gt;. Turn this option to true and you&amp;#8217;ll quickly see repaints as the happen!&lt;/p&gt;&lt;p&gt;&lt;em&gt;At the time of publish, only nightly exposed this config feature.&lt;/em&gt;&lt;/p&gt;&lt;p&gt;I recommend you take a few moments to scope out the repaint frequency on your websites and see what you can do to improve performance!&lt;/p&gt;&lt;p&gt;&lt;a
href="http://davidwalsh.name/browser-repaint"&gt;View Browser Repaints in Google Chrome and Mozilla&amp;nbsp;Firefox&lt;/a&gt; is a post from: &lt;a
href="http://davidwalsh.name"&gt;David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.&lt;/a&gt;&lt;/p&gt; &lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/U-1VmT48FVo" height="1" width="1"/&gt;</content><link href="http://davidwalsh.name/dw-content/ChromeBrowserRepaint.mp4" rel="enclosure" length="0" type="video/mp4" /><link href="http://davidwalsh.name/dw-content/MozillaNightlyRepaint.mp4" rel="enclosure" length="0" type="video/mp4" /><link rel="replies" type="text/html" href="http://davidwalsh.name/browser-repaint#comments" thr:count="2" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/browser-repaint/feed/atom" thr:count="2" /> <thr:total>2</thr:total> <feedburner:origLink>http://davidwalsh.name/browser-repaint</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[Load CSS Files via AMD with&#160;XStyle]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/X1xQS9EejFw/amd-xstyle" /> <id>http://davidwalsh.name/?p=5408</id> <updated>2012-03-27T15:54:41Z</updated> <published>2012-03-27T15:54:41Z</published> <category scheme="http://davidwalsh.name" term="CSS" /><category scheme="http://davidwalsh.name" term="JavaScript" /> <summary type="html"><![CDATA[AMD loaders are letting us load just about anything: AMD modules, basic JavaScript files (from any origin), text-based files (HTML templates, for example), and more. Unfortunately most loaders don&#8217;t have CSS loading capabilities, most likely because &#8220;onLoad&#8221;-style events aren&#8217;t provided by all browsers for stylesheets. Luckily my SitePen colleague Kris Zyp has created XStyle, an [...]<p><a
href="http://davidwalsh.name/amd-xstyle">Load CSS Files via AMD with&nbsp;XStyle</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></summary> <content type="html" xml:base="http://davidwalsh.name/amd-xstyle">&lt;p&gt;AMD loaders are letting us load just about anything: AMD modules, basic JavaScript files (from any origin), text-based files (HTML templates, for example), and more.  Unfortunately most loaders don&amp;#8217;t have CSS loading capabilities, most likely because &amp;#8220;onLoad&amp;#8221;-style events aren&amp;#8217;t provided by all browsers for stylesheets.  Luckily my SitePen colleague Kris Zyp has created XStyle, an AMD package available to AMD loaders for reliable stylesheet loading.  Let&amp;#8217;s take a brief look at XStyle!&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="https://github.com/kriszyp/xstyle" rel="nofollow" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;In fairness to XStyle, it&amp;#8217;s more than just an AMD plugin for loading stylesheets.  XStyle provides the capability to:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Shim and extend CSS&lt;/li&gt;&lt;li&gt;Load stylesheets and execute callbacks&lt;/li&gt;&lt;li&gt;Nested @import loading&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Shimming and extending CSS is great but doesn&amp;#8217;t seem to be something I would need often;  loading CSS with JavaScript modules is nice because:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Loading modules and templates together but needing to add LINK tags manually sucks&lt;/li&gt;&lt;li&gt;One define() to define a &lt;em&gt;complete&lt;/em&gt; widget from JS, to template, and CSS, is ideal;  especially for third party components&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;So consider a great JavaScript loader like &lt;a
href="https://github.com/cujojs/curl" rel="nofollow"&gt;curl.js&lt;/a&gt;.  With curl.js, all you need to do to load a CSS file is:&lt;/p&gt;&lt;pre class="js"&gt;
curl(["css!path/to/file.css"], function() {
    // defineCSS loaded, do stuff!
});
&lt;/pre&gt;&lt;p&gt;Sweet, right?  With a different loader, you can load your CSS files with other modules by coding:&lt;/p&gt;&lt;pre class="js"&gt;
define(["xstyle!./path/to/file.css"], function(){
    // module starts after css is loaded
});
&lt;/pre&gt;&lt;p&gt;Outstanding!  With XStyle we can define a &lt;em&gt;complete&lt;/em&gt; component, stylesheet and all!&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="https://github.com/kriszyp/xstyle" rel="nofollow" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;XStyle is capable of much more than what I&amp;#8217;ve presented above, but just the ability to load stylesheets with every other piece of a given module is priceless.  Improves organization and speed of coding;  well done Kris!&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;a
href="http://davidwalsh.name/amd-xstyle"&gt;Load CSS Files via AMD with&amp;nbsp;XStyle&lt;/a&gt; is a post from: &lt;a
href="http://davidwalsh.name"&gt;David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.&lt;/a&gt;&lt;/p&gt; &lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/X1xQS9EejFw" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/amd-xstyle#comments" thr:count="0" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/amd-xstyle/feed/atom" thr:count="0" /> <thr:total>0</thr:total> <feedburner:origLink>http://davidwalsh.name/amd-xstyle</feedburner:origLink></entry> <entry> <author> <name>David Walsh</name> <uri>http://davidwalsh.name</uri> </author><title type="html"><![CDATA[curl.js: Incredible AMD&#160;Loader]]></title><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/Bludice/~3/J-BUdadt2ew/curljs" /> <id>http://davidwalsh.name/?p=5383</id> <updated>2012-03-26T13:40:50Z</updated> <published>2012-03-26T13:40:50Z</published> <category scheme="http://davidwalsh.name" term="AJAX" /><category scheme="http://davidwalsh.name" term="JavaScript" /> <summary type="html"><![CDATA[Today there are dozens of AMD JavaScript loaders available, the most popular being RequireJS. There are also lesser known JavaScript loaders like YepNope, $script.js, LABjs, and Dojo&#8217;s new native loader. My favorite JavaScript loader, however, is John Hann (unscriptable)&#8217;s curl. While allowing for maximum configuration and reliable loading, curl also allows for loading of simple [...]<p><a
href="http://davidwalsh.name/curljs">curl.js: Incredible AMD&nbsp;Loader</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></summary> <content type="html" xml:base="http://davidwalsh.name/curljs">&lt;p&gt;Today there are dozens of AMD JavaScript loaders available, the most popular being RequireJS.  There are also lesser known JavaScript loaders like YepNope, $script.js, LABjs, and Dojo&amp;#8217;s new native loader.  My favorite JavaScript loader, however, is John Hann (unscriptable)&amp;#8217;s &lt;a
href="https://github.com/unscriptable/curl"&gt;curl&lt;/a&gt;.  While allowing for maximum configuration and reliable loading, curl also allows for loading of simple JavaScript files as well as CSS files.  Let me show you how to use it!&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="https://github.com/unscriptable/curl" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2&gt;Super Quick AMD&amp;nbsp;Primer&lt;/h2&gt;&lt;p&gt;If you aren&amp;#8217;t familiar with AMD structure, I&amp;#8217;m going to give you the most oversimplified explanation you&amp;#8217;ll ever hear.  AMD is a system by which you define and require modules asynchronously.  A define returns one or zero objects.  The first argument of both define and require is (usually) an array of dependencies.  The second argument is a function;  the define returns the result, the require executes a basic callback:&lt;/p&gt;&lt;pre class="js"&gt;
// "define" a module
define(["namespace/dependencyA", "namespace/dependencyB"], function(depA, depB) {
	// Whole bunch of processing
	
	
	// Return what this module defines
	return function() {
		// Or an object, or whatever
	}
});

// "require" to use modules:
require(["namespace/dependencyC"], function(depC) {
	
	// depC can be used in here only
	// Yay for modularity!
	
});
&lt;/pre&gt;&lt;p&gt;The slashes in the dependency array items represent paths to module JavaScript files.  Once dependencies are loaded, the action is allowed to begin.&lt;/p&gt;&lt;p&gt;&lt;em&gt;As I said, this is a very simple, vanilla example;  there are exceptions to every rule, so don&amp;#8217;t bother pointing out what-ifs.&lt;/em&gt;&lt;/p&gt;&lt;h2&gt;Configuring Module Loading with&amp;nbsp;curl&lt;/h2&gt;&lt;p&gt;And of course I start out with a few of the exceptions to the rule.  Instead of a &lt;code&gt;require&lt;/code&gt; function, curl.js defines &lt;code&gt;curl&lt;/code&gt; in its place.  Additionally, curl.js allows for an object literal as a first parameter, allowing for configuration of loaded modules:&lt;/p&gt;&lt;pre class="js"&gt;
curl({
		baseUrl: "/path/to/js",
		pluginPath: "curl/src/curl/plugin"
	}, 
	["namespace/depC", "namespace/otherDep"],
	function(depC, otherDep) {
		// Do stuff
	}
);
&lt;/pre&gt;&lt;p&gt;This configuration allows you to provide plugin paths, modules paths, and more.&lt;/p&gt;&lt;h2&gt;Basic define and require with&amp;nbsp;curl.js&lt;/h2&gt;&lt;p&gt;Basic usage of curl.js is as you would expect from a JavaScript loader;  dependency array as the first argument, callback with the second:&lt;/p&gt;&lt;pre class="js"&gt;
define(["namespace/depA", "namespace/depB"], function(depA, depB) {
	// Do something with the dependencies
	
	// Pump out a return obj
	return myFinalObject;
});
&lt;/pre&gt;&lt;p&gt;With a module defined, the same syntax requires and works with the dependencies:&lt;/p&gt;&lt;pre class="js"&gt;
curl(["namespace/depC"], function(depC) {
	// Do some stuff!
});
&lt;/pre&gt;&lt;p&gt;This is the same syntax you will have used with any JS loader, with the obvious exception of &lt;code&gt;require&lt;/code&gt; being replaced by &lt;code&gt;curl&lt;/code&gt;.&lt;/p&gt;&lt;h2&gt;curl.js with&amp;nbsp;next&lt;/h2&gt;&lt;p&gt;The next method allows for chaining of module loading:&lt;/p&gt;&lt;pre class="js"&gt;
curl(["js!someFile.js"])
	.next(["dep1", "dep2", "dep3"], function (dep1, dep2, dep3) {
		// Execute regardless of domReady status
	})
	.next(["domReady!"])
	.then(
		function () {
		// do something after the dom is ready
		},
		function (ex) {
		// show an error to the user
		}
	);
&lt;/pre&gt;&lt;p&gt;This syntax may suit your fancy more than others.&lt;/p&gt;&lt;h2&gt;curl.js with Deferred&amp;nbsp;Syntax&lt;/h2&gt;&lt;p&gt;If you work with the Dojo Toolkit, or more recently with jQuery, Deferreds are becoming more prevalent and incredibly useful;  curl.js provides you the ability to write your loader JavaScript in the same fashion:&lt;/p&gt;&lt;pre class="js"&gt;
curl(["namespace/depA"]).then(
	function(depA) { // success callback
	
	},
	function(depB) { // errback
	
	}
);
&lt;/pre&gt;&lt;p&gt;The deferred format and ability to pass the result of an XHR pool can be very powerful.&lt;/p&gt;&lt;h2&gt;Loading Non-AMD JavaScript&amp;nbsp;Files&lt;/h2&gt;&lt;p&gt;Sometimes you need to load JavaScript files that aren&amp;#8217;t in AMD format, like loading MooTools or jQuery from CDN.  curl.js makes that easy:&lt;/p&gt;&lt;pre class="js"&gt;
curl(
	["js!https://ajax.googleapis.com/ajax/libs/mootools/1.4.1/mootools-yui-compressed.js"]
).next(["namespace/MooModule"], function() {
	// We loaded Moo first, then once loaded, loaded a dependency that requires MooTools
	// At this point, both are loaded and we can work with them!
	
});
&lt;/pre&gt;&lt;p&gt;All you need to do add the &lt;code&gt;js!&lt;/code&gt; prefix to the dependency string and you&amp;#8217;re set;  your callback will be fire when the basic JavaScript file is loaded.  Note that you can mix AMD modules with basic JavaScript files:&lt;/p&gt;&lt;pre class="js"&gt;
curl(
	[
		"js!https://ajax.googleapis.com/ajax/libs/mootools/1.4.1/mootools-yui-compressed.js",
		"js!http://davidwalsh.name/mootools-ftw.js",
		"namespace/independentModule"
	]
).next(["namespace/MooModule"], function() {
	// We loaded Moo first, then once loaded, loaded a dependency that requires MooTools
	// At this point, both are loaded and we can work with them!
	
});	
&lt;/pre&gt;&lt;h2&gt;Loading CSS&amp;nbsp;Files&lt;/h2&gt;&lt;p&gt;Of course one of the strengths of AMD is modularity, so why not load your stylesheets with your scripts?&lt;/p&gt;&lt;pre class="js"&gt;
curl(
	[
		"namespace/MyWidget",
		"css!namespace/resources/MyWidget.css"
	], 
	function(MyWidget) {
		// Do something with MyWidget
		// The CSS reference isn't in the signature because we don't care about it;
		// we just care that it is now in the page
	}
});
&lt;/pre&gt;&lt;p&gt;LINK tags don&amp;#8217;t provide an onLoad event in all browsers, but curl.js&amp;#8217; shim provides a reliable method of detecting stylesheet load.  Since stylesheets are a large part of UI-driven, JavaScript-powered widgets, creating modules with stylesheet dependencies is becoming much more abundant.&lt;/p&gt;&lt;h2&gt;More curl&amp;nbsp;Plugins&lt;/h2&gt;&lt;p&gt;curl is much more than just a basic JS loader.  I&amp;#8217;ve already mentioned the JS and CSS plugins above, but curl has a few more.  curl features a domReady  plugin, as well as a text plugin and an internationalization plugin:&lt;/p&gt;&lt;pre class="js"&gt;
curl(
	[
		"i18n!stuff/nls/strings", // Load string content for the user's namespace
		"text!myWidget/resources/template.html", // Loads a file as text,
		"domReady!" // Don't fire the callback until the DOM is ready
	],
	function(nlsStringObject, template) { // Callback
		// Do something now that we have the NLS object, template, and domContentLoaded has fired
	}
);
&lt;/pre&gt;&lt;p&gt;These plugins are quick and easy enhancers to existing functionality!&lt;/p&gt;&lt;div
class="actions"&gt;&lt;a
href="https://github.com/unscriptable/curl" class="demo"&gt;View Demo&lt;/a&gt;&lt;div
class="clear"&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;curl is an absolute beast of a JavaScript loader.  Beyond simple AMD loading, curl is fit with numerous configuration options, plugins, and multiple syntax structures to all the developer to code the way they want.  This blog uses curl.js to asynchronously load JavaScript modules and stylesheets, manage domReady, and more;  the best endorsement I can give!&lt;/p&gt;&lt;p&gt;&lt;a
href="http://davidwalsh.name/curljs"&gt;curl.js: Incredible AMD&amp;nbsp;Loader&lt;/a&gt; is a post from: &lt;a
href="http://davidwalsh.name"&gt;David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.&lt;/a&gt;&lt;/p&gt; &lt;img src="http://feeds.feedburner.com/~r/Bludice/~4/J-BUdadt2ew" height="1" width="1"/&gt;</content><link rel="replies" type="text/html" href="http://davidwalsh.name/curljs#comments" thr:count="2" /><link rel="replies" type="application/atom+xml" href="http://davidwalsh.name/curljs/feed/atom" thr:count="2" /> <thr:total>2</thr:total> <feedburner:origLink>http://davidwalsh.name/curljs</feedburner:origLink></entry> </feed><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/63 queries in 0.053 seconds using disk: basic
Object Caching 1530/1645 objects using disk: basic

Served from: davidwalsh.name @ 2012-04-28 23:08:53 -->

