<?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>Wayne Pan &#187; sharethis</title>
	<atom:link href="http://waynepan.com/tag/sharethis/feed/" rel="self" type="application/rss+xml" />
	<link>http://waynepan.com</link>
	<description>tech &#124; js &#124; ui &#124; ajax &#124; mobile</description>
	<lastBuildDate>Fri, 03 Sep 2010 22:16:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Dissecting ShareThis Widget (BAD) Javascript Code</title>
		<link>http://waynepan.com/2008/04/21/dissecting-sharethis-widget-bad-javascript-code/</link>
		<comments>http://waynepan.com/2008/04/21/dissecting-sharethis-widget-bad-javascript-code/#comments</comments>
		<pubDate>Mon, 21 Apr 2008 08:14:02 +0000</pubDate>
		<dc:creator>Wayne</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[sharethis]]></category>

		<guid isPermaLink="false">http://waynepan.com/?p=124</guid>
		<description><![CDATA[I just installed the ShareThis button on this blog so I cracked open the javascript payload. You can view it here. In short, it&#8217;s horrific! It pains me to see this because this is a widget which means this code &#8230; <a href="http://waynepan.com/2008/04/21/dissecting-sharethis-widget-bad-javascript-code/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href='http://sharethis.com'><img src="http://waynepan.com/wp-content/uploads/2008/04/sharethis_logo_tm.gif" alt="" title="sharethis_logo_tm" width="197" height="40" class="aright" /></a>I just installed the <a href="http://sharethis.com/">ShareThis</a> button on this blog so I cracked open the javascript payload. You can <a href="http://w.sharethis.com/widget/">view it here</a>. In short, it&#8217;s horrific! It pains me to see this because this is a widget which means this code is running a million times a day!</p>
<p>First, let&#8217;s get some basics out of the way.</p>
<ul>
<li>Comments and white-spaces are left in the code, increasing the payload size. I suggest using <a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a> before posting the code.</li>
<li><i>Lines 1-3</i> &#8211; MooTools is included at the top of the script, PACKED. Thanks to <a href="http://jst.pbwiki.com/summary.php">PB Wiki&#8217;s Tests</a>, we now know this is bad for client side performance. Stop doing this, see above!</li>
<li><i>Lines 3-12</i> &#8211; They&#8217;ve included the FireBug Lite code to account for the 5 occurrences where they use console. Remove the 5 debug statements that don&#8217;t do squat and you can shave off ~350 bytes</li>
</ul>
<p>Doing the above netted a 6940 bytes savings or a script 65% the size of the original (not to mention the client side cycles shaved off by removing the packed mootools). Click the link below to view it.</p>
<blockquote><p>
13048 Apr 21 00:17 <a href="http://waynepan.com/wp-content/uploads/2008/04/sharethis_widget_better.js">sharethis_widget_better.js</a><br />
19988 Apr 21 00:18 <a href="http://waynepan.com/wp-content/uploads/2008/04/sharethis_widget_original.js">sharethis_widget_original.js</a>
</p></blockquote>
<p>Digging into the code further I found a lot of various space saving things that could be done in the code (using radix in parseInt, avoiding at least one try catch block <i>83-89</i>, etc). Also a few oddities like lines <i>329 &#8211; 332</i> (which looks like a bug), just asking for trouble by using _s in the global space, and wtf is going on with lines <i>460-464</i>? Declaring _query to be [] then passing it to the ShareThis object, which from what I can tell doesn&#8217;t do anything, then setting the query property again to _query (which is really []) and then pointlessly setting a variable st to the newly created ShareThis. </p>
<p>I know I&#8217;m guilty of writing bad javascript also, but if you&#8217;re a company distributing a widget you should at least clean up the code a tad&#8230; ironically the ShareThis widget appears immediately after this line. =|</p>
]]></content:encoded>
			<wfw:commentRss>http://waynepan.com/2008/04/21/dissecting-sharethis-widget-bad-javascript-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
