103 points · by joshuacc · 14y ago · 69 comments
It has a compatible syntax at a third of the weight. It's very well suited to mobile.
With regards to the original post; it's fantastic to be doing things efficiently, but in the vast majority of circumstances I would presume that forcing the user's browser to download some additional kb of libraries is preferable to forcing the user to Google a currency conversion.
If you're starting now, you can build effectively in JavaScript alone. That said, you may still benefit from a framework if you're doing a very large, long-term project.
No version of Safari supports bind.
If your experiences indicate otherwise, you are simply doing something wrong.
PS. jQuery is horrible. Every time you think you've figured out all of their undocumented quirks, they change the logic. It's famously inept in IE 6/7.
I will say though, it sure is nice not having to deal with all of the browser weirdness that you face without a lib like jquery.
Then have a jQuery-like API when it's useful or improves clarity.
And if you "enjoy" jQuery, you have no frame of reference. It's far more inconsistent than the DOM implementations and the documentation is terrible.
What quirks is jquery saving you from dealing with? There are some, but I'd like the reader to actually think about this for a moment.
Many simply defer to jquery now and have lost curiosity about the underlying browsers (which have been rapidly improving).
Oh and try querying for something like this in ie6.
'.class + .other_class > .yet_another_class'
Having css3 query support in legacy browsers is awesome.
Not to mention productivity gains from method chaining and batch assignment such as
$('.somehting').find('*').css({'font-weight': 'bold'});
Do you really want to type the 10-20 lines of JS that are required to make that happen? I don't.
I used to do a lot of work in Flash, and one of the nicest parts was knowing that what you write works as intended across environments. One of the nice side-effects of the HTML5 mob is that the browser vendors are putting a lot of work into both improving their APIs and doing so in a cross-compatible way.
We've gotten to such a point of jQuery saturation that it seems some of us have forgotten why we use it in the first place. Which is really just the other side of the coin of people blindly using it without knowing why.
Selectors are completely unnecessary. Class "selectors" are tar pits as they have to search every single node in the current context (usually the entire DOM) and then have to check for a class match amongst a possibility of multiple classes.
Quite simply, if you're using a class "selector", you're doing the user—and yourself—a great disservice. Use `id` hooks where possible and `HTMLCollection`s like `HTMLDocument::forms` and `HTMLFormElement::elements` when `id`s are unnecessary. The speed gains are huge.
Moreover, jQuery completely loses its appeal once the selectors are eschewed. The only legitimate options I see are the `classList` abstractions along with the animation methods. Both are easily replaced with far more modular options (I prefer David Mark's My Library).
In short, please learn about the DOM and how it operates. The browser "weirdness" tends to sort itself out once you realize what's going on.
Then instead of 628 bytes, you'll have just 100 or so. Then make the script loader a re-usable function for other data on the page.
For instance, just recently I was looking into plug-ins for automatically changing text and color of input fields, but I only needed it once, and I ultimately decided it was much more efficient to just manually code this into the onclick:
> if(this.value==\'Search Products\'){ this.value=\'\';this.style.color=\'#000\';}
I haven't dug into the code, but doesn't jQuery already use native methods like querySelectorAll where available?
I guess if all you need is to query the document and you know your target audience is running a modern browser... then sure, save yourself 31k :)
Yes. But it still has quite a bit of overhead as it also handles non-standard selectors (implemented in javascript), things like :input.
> I guess if all you need is to query the document and you know your target audience is running a modern browser... then sure, save yourself 31k :)
If you've got an ever more restricted target audience, you can also use things like Zepto (webkit-only, jQuery's interface in 7k)
"How's" are easily Googleable, "why's" are a little harder and therefore more valuable, IMO.
Especially when I consider that we're delivering a 350KiB minified Javascript hit on initial load just for jquery and a load of plugins.