views:

81

answers:

2

I've just come to the end of a large development project. We were on a tight timeline, so a lot of optimization was "deferred". Now that we met our deadline, we're going back and trying to optimize things.

My questions is this: What are some of the most important things you look for when optimizing jQuery web sites. Alternately I'd love to hear of sites/lists that have particularly good advise for optimizing jQuery.

I've already read a few articles, http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx was an especially good read.

+2  A: 

@aepheus, here is another site for reference: www.artzstudio.com/2009

Check out #8 on Eliminate Query waste. hth

nolabel
A: 

mostly i look at selectors that repeat themselfs.. most of the times these can be saved into a variable and used over and over, for example:

$('.some_class').doSomthing();
$('.some_class').doSomethingElse();

can be turned into:

selectedItems = $('.some_class');
selectedItems.doSomething(); selectedItems.doSomethingElse();

this way the selector goes over the DOM once... then you can continue to use the variable as a jquery object thanks to the fact that every jquery method returns the jquery object.

Just one tip out of many out there...

Ken
Or into `$('.some_class').doSomething().doSomethingElse()`. Might seem awkward at first but it's a really useful feature.
Felix
yes of course you're right - but it doesn't always work for every situation... mostly it does, but some end cases you might need separate operations
Ken
While something like this would significantly help reduce overhead (making one selector call instead of two) I would guess that changing to $('td.some_class') in many contexts would give more of a bonus than chaining would.
aepheus
of course.. my 2 cents was regarding saving on selecting twice - and not on optimizing the selector itself; which is a subject all of its own (covered in depth in the links other provided).
Ken