<?xml version="1.0"?>
<rss version="2.0"><channel><title>Flow of Logic</title><link>http://flowoflogic.com</link><description>Thoughts and Ramblings</description><lastBuildDate>Wed, 08 Apr 09 01:18:04 -0700</lastBuildDate><generator>Habari 0.5.2 http://habariproject.org/</generator><item><title>My problem with JavaScript libraries</title><link>http://flowoflogic.com/my-problem-with-javascript-libraries</link><description>&lt;p&gt;I have a problem with JavaScript libraries. My problem is this: I feel that, in a way, they begin to replace actual JavaScript for new web developers. Let's say I teach a person to use jQuery. I teach him to use the various functions, and how to use plugins. Then, I see him working on a project one day and see this code:&lt;/p&gt;&#xD;
&#xD;
&lt;pre&gt;&#xD;
&amp;lt;script type="text/javascript"&amp;gt;&#xD;
$(function() {&#xD;
	$("#hide").hide();&#xD;
	$("#show").show();&#xD;
}&#xD;
&amp;lt;/script&amp;gt;&#xD;
&lt;/pre&gt;&#xD;
&#xD;
&lt;p&gt;That's right, he's importing 20kb of pure JavaScript awesomeness for... two lines of code that could have just as easily been done using raw JavaScript:&lt;/p&gt;&#xD;
&#xD;
&lt;pre&gt;&#xD;
&amp;lt;script type="text/javascript"&amp;gt;&#xD;
	document.getElementById('hide').style.display = 'none';&#xD;
	document.getElementById('show').style.display = 'block';&#xD;
&amp;lt;/script&amp;gt;&#xD;
&lt;/pre&gt;&#xD;
&#xD;
&lt;p&gt;There's a plugin for jQuery that allows for slideshows known as jQuery Cycle. It weighs in at a hefty 28kb when compressed. However, when I see it in the wild, often I see that they only use it for the base fade in/out feature.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;There's a version of jQuery Cycle aptly named jQuery Cycle Lite that provides only this function, leaving out the many cool but underused features of the full version. This one weighs in at 3kb compressed.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Recently, my friend, colleague, and fellow writer at our blog &lt;a href="http://www.lateralcode.com/"&gt;Lateral Code&lt;/a&gt;, Karthik Viswanathan, wrote &lt;a href="http://www.lateralcode.com/simple-slideshow/"&gt;a very simple jQuery-based slideshow&lt;/a&gt;. It only does a fade in/out effect, but it only takes 300kb &lt;em&gt;uncompressed&lt;/em&gt;. Take a look:&lt;/p&gt;&#xD;
&#xD;
&lt;pre&gt;&#xD;
&amp;lt;script type="text/javascript"&amp;gt;&#xD;
$('.ppt li:gt(0)').hide();&#xD;
$('.ppt li:last').addClass('last');&#xD;
var cur = $('.ppt li:first');&#xD;
&#xD;
function animate() {&#xD;
	cur.fadeOut( 1000 );&#xD;
	if ( cur.attr('class') == 'last' )&#xD;
		cur = $('.ppt li:first');&#xD;
	else&#xD;
		cur = cur.next();&#xD;
	cur.fadeIn( 1000 );&#xD;
}&#xD;
&#xD;
$(function() {&#xD;
	setInterval( "animate()", 5000 );&#xD;
} );&#xD;
&amp;lt;/script&amp;gt;&#xD;
&lt;/pre&gt;&#xD;
&#xD;
&lt;p&gt;That is it. That's literally everything he needs other than jQuery to get that working. Do web developers need to reconsider their approach to JavaScript? Or is it fine to just continue plodding along teaching our pupils that JavaScript libraries are the best, letting them import 20kb just to hide an element?&lt;/p&gt;</description><pubDate>Wed, 08 Apr 09 01:18:04 -0700</pubDate><guid isPermaLink="false">tag:flowoflogic.com,2009:my-problem-with-javascript-libraries/1239178725</guid></item></channel></rss>
