<?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>No Mod Required &#187; Code I Like</title>
	<atom:link href="http://www.drunkenfist.com/304/category/web/code-i-like/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.drunkenfist.com/304</link>
	<description>Rob Larsen writes on entertainment, sports and culture.</description>
	<lastBuildDate>Wed, 08 Feb 2012 02:28:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Code I Like &#8211; Link Prefetching</title>
		<link>http://www.drunkenfist.com/304/2008/11/24/code-i-like-link-prefetching/</link>
		<comments>http://www.drunkenfist.com/304/2008/11/24/code-i-like-link-prefetching/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 21:35:45 +0000</pubDate>
		<dc:creator>rob</dc:creator>
				<category><![CDATA[Code I Like]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[tips-and-tricks]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.drunkenfist.com/304/?p=5119</guid>
		<description><![CDATA[I was reading John Resig's Browser Page Load Performance post earlier today and followed up from there on the concept of Link prefetching. Currently supported by Firefox 2+, Link prefetching is a browser based mechanism for fetching "future" content. Considering I wrote (and ultimately scrapped*) similar functionality for my gallery pages, I was obviously intrigued. [...]]]></description>
			<content:encoded><![CDATA[<p>I was reading John Resig's <a href="http://ejohn.org/blog/browser-page-load-performance/">Browser Page Load Performance</a> post earlier today and followed up from there  on the concept of Link prefetching. Currently supported by Firefox 2+, <a href="https://developer.mozilla.org/en/Link_prefetching_FAQ">Link prefetching</a> is a browser based mechanism for fetching "future" content. Considering I wrote (and ultimately scrapped*) similar functionality for my gallery pages,  I was obviously intrigued.<br />
<span id="more-5119"></span><br />
In its basic version it looks like this:</p>
<p><code>&lt;link rel=&quot;prefetch&quot; href=&quot;/images/big.jpeg&quot;&gt;</code></p>
<p>With the <code>href</code> being the target content and the <code>rel</code> attribute triggering the prefetching mechanism. Pretty simple. I've already implemented it here on my gallery pages.</p>
<p>One thing I would like to see, <a href="https://developer.mozilla.org/en/Link_prefetching_FAQ#Are_anchor_(.3ca.3e)_tags_prefetched.3f">and this is hinted at on the above linked Mozilla FAQ page</a>, is prefetching performed automatically on anchor (&lt;a&gt;) tags with <code>rel</code> attribute set appropriately. In my mind that would be any anchor with a <code>rel</code> attribute of  <code>next</code>, but the <code>prefetch</code> value would be fine as well. Personally, if that were supported I wouldn't have any (or very little) work to do to take advantage of this feature and in a general sense it would build on what people are already doing using <code>prev</code>, <code>next</code> and <code>toc</code> <code>rel</code> attributes on gallery links.</p>
<p>*it was scrapped because I hated the idea of forcing bandwidth usage on people with metered accounts. Since this is a browser based mechanism, it should be relatively painless for people in that situation to control whether or not content is prefetched. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.drunkenfist.com/304/2008/11/24/code-i-like-link-prefetching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code I Like: A JavaScript Object as an Argument for a Function</title>
		<link>http://www.drunkenfist.com/304/2008/09/01/code-i-like-a-javascript-object-as-an-argument-for-a-function/</link>
		<comments>http://www.drunkenfist.com/304/2008/09/01/code-i-like-a-javascript-object-as-an-argument-for-a-function/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 20:39:34 +0000</pubDate>
		<dc:creator>rob</dc:creator>
				<category><![CDATA[Code I Like]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.drunkenfist.com/304/?p=4798</guid>
		<description><![CDATA[This will hopefully be the first of a continuing series of smaller code articles where I share techniques I (and my team) use on a daily basis. I take this stuff for granted so I think it might be beneficial to share since (a) I might be able to improve what I do by receiving [...]]]></description>
			<content:encoded><![CDATA[<p>This will hopefully be the first of a continuing series of smaller code articles where I share techniques I (and my team) use on a daily basis. I take this stuff for granted so I think it might be beneficial to share since (a) I might be able to improve what I do by receiving feedback on techniques I use and (b) some of the things I do, while old hat to me, might be new and useful to other people in the field. </p>
<p>We'll see how it goes.<br />
<span id="more-4798"></span><br />
With that short into out of the way I wanted to start off with a bit of JavaScript that I really appreciate, namely using a JavaScript Object as the argument for a function when multiple options are possible.</p>
<div class="code_sample"><code>
<pre>
<em>//Here's what a function call looks like</em>

document.getElementById("myObject").onclick = doSomething(
<em>//here's the object</em>
	{
		<em>//I'm using 3 options here</em>
		file: "/_assets/images/object.jpg",
		messageText: "Objects sure are swell",
		newUrl: "/object.php"
	}
);

<em>//and here's a snippet of the function definition</em>
function doSomething( options ) {
<em>//here we either use the arguments supplied in the call
//or  fall back to defaults.
//notice how the order is off and how callback
//was never supplied in the function call</em>
	options = {
		file: options.file || "",
		callback : options.callback || function(){},
		newUrl: options.newUrl || "http://www.google.com/",
		messageText: options.messageText || "You love Objects"
    };
//stuff happens
};
</pre>
<p></code></div>
<p>Why do I like this? Two things:</p>
<ol>
<li>I don't need to remember the order of arguments and I don't need to supply blank arguments if I'm not using one. I can't tell you the number of times I've messed up the order of arguments and cased an error which I then had to do a couple of minutes of research to fix. I still do it with the addClass, removeClass, hasClass, toggleClass suite I use pretty much every time I write JavaScript and that's only <strong>two</strong> arguments. If I converted those to a single Object it would be grand since I know I'd remember <code>obj</code> (my default Object argument name) and <code>className</code>.
<p>&#8230;and forget about remembering where to put unused arguments. That's the pits.
</li>
<li>It's conceptually much clearer. Organizationally it's much cleaner to me (especially the way the defaults are spelled out right at the top of the function) and the Object labels take any guesswork out of the arguments when the function is called. I know exactly what I'm doing when I call a function defined this way. Compare the Object pattern to this classic:
<p><code>"MM_swapImage('Image1','','/img/newImg.jpg',1)"</code></p>
<p>Quick, without referring to anything else, what's going on there?</p>
<p>Sure, the first is the image name and the third is the image name, but what are the other two?  Off-hand I'd have no idea and that's one of the most common blocks of code on the internet. Compare that to an object version:</p>
<p><code>
<pre>
swapImage( {
	target: 'Image1',
	swapFrame: "",
	fileName: '/img/newImg.jpg',
	preload : 1
});</pre>
<p></code></p>
<p>That brings clarity, right? Stunning clarity for me as I never knew what that always-blank second argument was.</li>
</ol>
<p>And there you have it, the first installment. There will be a lot of CSS and HTML in this series as well, so if they float your boat as well <a href="http://www.drunkenfist.com/304/category/web/code-i-like/">please keep your eyes peeled</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.drunkenfist.com/304/2008/09/01/code-i-like-a-javascript-object-as-an-argument-for-a-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

