top | item 5547732

(no title)

mddw | 13 years ago

"I encourage you to give it a shot. Write your next application, library or just code for fun without jQuery. "

Been there, done that. And it's a pain in the *

You'll find yourself needing a method to add or remove classes eficiently. So you'll rewrite .addClass() and .removeClass()

Then you'll need a clean way to make Ajax and callbacks. You'll rewrite .ajax() and .when()

Then you'll need to fade something in all browser. So you'll rewrite .animate()

Ad lib.

JQuery Minified and GZipped is 35k (not 90 as the op said, ignoring the gziping.) JQuery is cached in most browsers. The performance hit is not worth the pain of re-inventing the wheel.

The problem is not JQuery, it's bad code. Bad code won't magically disappear in vanilla JS.

discuss

order

gildas|13 years ago

> You'll find yourself needing a method to add or remove classes eficiently. So you'll rewrite .addClass() and .removeClass()

You don't need to rewrite it, cf. this shim [1] for example.

> Then you'll need a clean way to make Ajax and callbacks. You'll rewrite .ajax() and .when()

They are plenty of good Ajax implementations, for example this one [2]. If you need promises, there are good libraries too [3].

> Then you'll need to fade something in all browser. So you'll rewrite .animate()

Applying a fading effect on an element shouldn't be a mandatory feature. You can just use CSS3.

[1] https://developer.mozilla.org/en-US/docs/DOM/element.classLi...

[2] http://jibbering.com/2002/4/httprequest.html

[3] https://github.com/kriskowal/q

nasmorn|13 years ago

Client: I want this element to fade out. Me: No problem but only on browsers with CSS3 support. Client: What is CSS3? Me: Let me say it differently, it wont work on some browsers. Client: Why, is it hard to do? Me: Not really, but I would need to use an open source library to do it. Client: But don't you usually tell me that that's a good thing. Me: Yes but see yesterday I someone on the Internet said it should not be a mandatory feature. Client: You are fired.

TazeTSchnitzel|13 years ago

>So you'll rewrite .addClass() and .removeClass()

Or, you'll use element.classList.add()

>You'll rewrite .ajax() and .when()

XHR isn't really too verbose.

>So you'll rewrite .animate()

Or you'll do elem.style.transition = ... and use elem.addEventListener;

Really, the plain DOM isn't that bad. If you make one or two sugar methods, they'll be far, far, far smaller than jQuery, and probably far faster.

mddw|13 years ago

classList won't work in IE < 10. XHR with promise is quite verbose. Transitions won't work in IE < 10. etc. These were examples, not a complete case list.

What's the point to use shims or polyfills if it means including some others libraries ?

JQuery is not slow. If you .addClass() two hundred divs, sure. But for basic DOM manipulations, it's fine.

JQuery is not heavy. 32kb. It may be in cache. You'll likely gain that twice 32kb by optimizing your png.

This anti-JQuery war is a silly fad started by people who don't make websites.

And as per arguments like "a fadein should not be mandatory blablabla", explain it to the client. It may work. Or it may not.

Finster|13 years ago

In fact, I think a case could be made that vanilla JS would encourage bad code.

neya|13 years ago

Well said!