Designing the Front-End
javascript
Finally Know jQuery and jQuery UI, In and Out
Nov 22nd
I am not new to jQuery and jQuery UI, in fact I have written quite few applications using these popular libraries. A few years ago I read Object Oriented Javascript and I liked the style in which it was written. It gave me a good base experience and understanding for structuring code properly. Using this book, the learning curve became easy and simple (especially while visiting the chapters dedicated to the concept of “inheritance,” which is really important to grasp for anyone developing serious javascript applications.After successfully gaining knowledge from Object Oriented Javascript, I decided to give Learning jQuery, Third Edition and jQuery UI 1.8 a try. I am glad to report both titles have nearly the same style of clarified learning, which is apparent in its simple language and comprehensible delivery. I’m certain that even if these concepts were foreign to me, learning through Learning jQuery and jQuery Ui would be a delightful breeze.
I loved these book for a few reasons:
- It first clearly explains the core concepts and then goes thru each method and utility in detail, so everything is very easy to understand.
- The tips and ‘Best Practices’ snippets are very useful. They helped me gain a lot of knowledge on how to structure both large and small apps, compose CSS properly and taught general good practices for UI stated css
I highly recommend you get your hand on the Learning jQuery, Third Edition and jQuery UI 1.8 . This recommendation stands for beginners and jQuery ninjas alike, as they both coves areas that are tremendously insightful for everyone. For a beginner, it is “THE book to read” for coherently and effectively learn jQuery. For the experts out there, it is clearly an eye opener on some very important topics, and I am certain that after giving it a read, anyone’s code will both preform better and be composed in a finer manner. Additionally, it also contains inordinately valuable day-to-day hard-to-find examples that will sure be cherished.
Sometimes over-optimizing jQuery causes script to run slower
Jul 3rd
Lately more and more developers are focusing on performance and it is a new hype in the javascript development world to optimize Javascript code.
Developers these days do not only care that their app works in all browsers etc. They will go the extra mile and ensure that the code is optimized and that the javascript execution time is the fastest it can be.
Recently i wrote a new jQuery plugin i tried to optimize the code as much as possible.
Looking at these 2 snippets:
$("div").width();
$("div").eq(0).width();
They return the same result.
Which one would be faster?
As you might know jQuery’s width() method returns the current computed width for the first element in the set of matched elements.
So I always thought why give jQuery the whole set just to get the first elements width, why not make it easier and pass only the first element in the collection by filtering the collection with .eq() to the width method.
It turns out that the width method itself handles it better.
See the results of the jsperf i put together.
The truth is, as @paulirish says “Don’t treat jQuery as a Black Box” always dig in to the source code and see what it does internally.
If you look in the jQuery’s fn.width source where you can see that jQuery filters out the first element the most native way it can and it does it right in the beginning of the function.
var elem = this[0];
Here are 2 videos in which paul digs into jQuery’s core.
10 things i learned from the jquery source
11 more things i learned from the jquery source