TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why It's Time to Sunset jQuery

64 点作者 jasoncrawford大约 12 年前

22 条评论

neya大约 12 年前
Is this a joke? A huge percentage of the web is running with Jquery. Jquery targets a different set of audience - Ones that want to do more stuff with less code. This type of audience doesn't care about performance (mostly) because it helps them get things done.<p>Think of it this way - Everyone loves Ruby on Rails. But Rails IS slow. But that doesn't mean I should re-write my code in just plain C, just because it is <i>fast</i> and Rails is no longer needed according to a bunch of bloggers.<p>I think this argument is not about Jquery and is about frameworks in general.<p>In my humble opinion, I think [1]<p><pre><code> $.ajax({ url: "test.html", context: document.body }).done(function() { $(this).addClass("done"); }); </code></pre> is better than:<p><pre><code> function ajaxFunction() { var ajaxRequest; // The variable that makes Ajax possible! try { // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e) { // Internet Explorer Browsers try { ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function () { if (ajaxRequest.readyState == 4) { var ajaxDisplay = document.getElementById('ajaxDiv'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } var age = document.getElementById('age').value; var wpm = document.getElementById('wpm').value; var sex = document.getElementById('sex').value; var queryString = "?age=" + age + "&#38;wpm=" + wpm + "&#38;sex=" + sex; ajaxRequest.open("GET", "ajax-example.php" + queryString, true); ajaxRequest.send(null); } </code></pre> [1]<a href="http://www.tizag.com/ajaxTutorial/ajax-javascript.php" rel="nofollow">http://www.tizag.com/ajaxTutorial/ajax-javascript.php</a>
评论 #5547699 未加载
评论 #5547894 未加载
评论 #5547700 未加载
评论 #5547467 未加载
评论 #5547616 未加载
ebbv大约 12 年前
This is hilariously wrong-headed.<p>- If you use the standard jQuery hosted off Google's CDN, most users won't have to load it in the first place. So that overhead doesn't count. Only if you do some boneheaded thing like rolling your own version and hosting it on your server are you going to guarantee every visitor has to download jQuery.<p>- Parsing jQuery is trivial for most modern browsers. If your web app has performance issues, it's not jQuery's fault, it's your fault.<p>- querySelectorAll is not a replacement for jQuery. If you think it is you haven't been making good use of jQuery.<p>This article seems like a post by someone who didn't even know how to do basic things against the DOM, finally learned how to do them and now thinks there's no use for jQuery. It's absurd.<p>jQuery still has plenty of uses. I'm not saying you have to use it, or are making a mistake if you don't, but the assertion that it should be abandoned is ludicrous.<p>Ugh.
评论 #5547718 未加载
评论 #5548210 未加载
mddw大约 12 年前
"I encourage you to give it a shot. Write your next application, library or just code for fun without jQuery. "<p>Been there, done that. And it's a pain in the <i></i>*<p>You'll find yourself needing a method to add or remove classes eficiently. So you'll rewrite .addClass() and .removeClass()<p>Then you'll need a clean way to make Ajax and callbacks. You'll rewrite .ajax() and .when()<p>Then you'll need to fade something in all browser. So you'll rewrite .animate()<p>Ad lib.<p>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.<p>The problem is not JQuery, it's bad code. Bad code won't magically disappear in vanilla JS.
评论 #5547984 未加载
评论 #5548151 未加载
评论 #5548437 未加载
评论 #5547864 未加载
ashray大约 12 年前
You know what I love about jQuery ? It's readable.<p>Every time I have to look at plain ol' javascript it feels like my eyes are going to bleed. Regardless of whether I wrote it myself or whether another developer wrote it.<p>On the other hand, jQuery (still not the Miss World of programming languages..) is far easier on the eyes.<p>Also, for most apps, the performance impact isn't all that noticeable since most of the performance hit happens due to reflows and not because of jQuery. Plus, the Google CDN jQuery is pretty well cached in most browsers.
评论 #5547636 未加载
评论 #5547982 未加载
evadne大约 12 年前
It might make sense to cherry pick jQuery features and build your own jQuery — if you absolutely need it, and absolutely can’t carry the whole library. In other cases I think it’s mostly just bikeshedding.<p>jQuery is there to minimize surprises. Native API is magnitudes faster — yes. It is also divergent across browser runtimes. Then you code for special cases and test by hand, now you’re building your own jQuery.<p>Maybe we have better things to do.
评论 #5547571 未加载
评论 #5547445 未加载
mmmelissa大约 12 年前
"first you need to make the assumption of a browser baseline. For me it is at least IE8, however that is quickly moving to IE 9 as most should upgrade to at least IE9, even stodgy old enterprises"<p><i></i><i>BAD ASSUMPTION</i><i></i> Just because they should doesnt mean they have or will anytime soon!!!<p>Have fun convincing my "stodgy old enterprise" to upgrade to IE9. They JUST upgraded to IE8! Yes, ideally no one should be using these crappy old browsers, and I champion this idea and all of the reasons why at work all the time. Rational arguments dont work in the kool-aid world of government. (Does it need to be said that I am looking for a new job?)<p>A lot of people browse the web from work, and so I dont think it is safe to ignore all of those crappy browsers yet.
ben336大约 12 年前
I felt like the article did a good job of explaining the potential replacements, but failed to make a convincing case for why the perfomance benefits outweigh the simplicity of jQuery. There's a conversation to be had about balancing those two, but this post makes the implicit assumption that performance is king and never really addresses the tradeoffs between performance and simplicity/familiarity.
评论 #5547579 未加载
SeanDav大约 12 年前
Considering that the highest version of IE that Windows XP can support is IE 8 and the large number of XP machines still out there - it will be fairly silly to not support IE 8 for at least a couple more years.
mosselman大约 12 年前
Have fun doing things like $('div').animate({opacity: '0.4', left: '10px', background-color: '#44444'}); in native js.<p>Of course you CAN do it... but do you want to?
评论 #5548017 未加载
eupharis大约 12 年前
Well, in the specific case of using native selectors (document.querySelector), I'm sold. It's supported very widely:<p><a href="http://dev.w3.org/2006/webapi/selectors-api-testsuite/level1-baseline-report.html" rel="nofollow">http://dev.w3.org/2006/webapi/selectors-api-testsuite/level1...</a><p>Wish I'd known about this before. I've been using $('#main').get(0) when I didn't want a jQuery object. Which is all kinds of silly.
sourc3大约 12 年前
The author's point is valid for selectors, but he is not considering the plethora of plug-ins that are built on top of jQuery and just work.<p>Until browsers can support all of that, I think we are a LONG way from saying goodbye to jQuery.<p>For all I know jQuery is saving me a ton of time when working on my prototype for the new side project. Last thing I want to do is to re-invent the wheel at my own expense :)
wildgift大约 12 年前
JS performance isn't that important for most tiny apps. It's client side code and distributed.<p>If JS performance were important, someone would write a jQuery -&#62; js compiler and produced compiled js as output. But they don't do that, because once you benchmark the code, you find out that DOM is very slow, as johnbender mentioned.<p>I'm still used to hacking in vanilla JS, but when I want to write something longer than a hundred lines, I load jQuery. It's the only sane tool to reduce code size. It does it in a pretty disciplined, lisp-y way, too.<p>It's liberal use of the $(selector).f(x).g(y).h(z) style, which applies the function to the previous result, which is a collection, helps you code at a higher level of abstraction. No more loop structures!<p>It's not time to sunset jQuery: it's time to put more support for jQuery style functions into ECMAScript, so you can get better performance though parallelization, lazy evaluation, etc.
eknkc大约 12 年前
DOM manipulation and querying is a small subset of what jQuery does. There's ajax, event handling, dom creation from html fragments, animations, utility functions, size / position / offset calculators etc. And there are messy cross browser stuff in there.<p>Yeah, let's get rid of it.
idan大约 12 年前
Not knowing the details of jQuery 2.0's cruft removal, I wonder how much the performance gap is closed by a jQuery that doesn't need to deal with Really Old Browsers™.
varunkho大约 12 年前
Everything moves in cycle. Yesterday I started coding and found fragmentation to be the biggest issue so I thought I needed a framework to do anything reasonable. That issue got solved and I have got used to it. So today I am finding that performance is the issue. I again decide to dich the framework and start hacking it by hand. Tomorrow I find ...<p>I focus more on tools rather than building things that matter in the end.
mistercow大约 12 年前
I've seen a couple of people talking this way lately, and while we might be able to start talking about this in five years, the idea that after IE8 (or even IE9), we're past the point of needing a library to abstract away the differences between browsers is pure fantasy.<p>As is the idea that now that we have querySelectorAll, the DOM suddenly isn't a complete nightmare of an API.
hcarvalhoalves大约 12 年前
jQuery exists because the native APIs available in browsers are not cross-compatible and suck at the same time. jQuery can be left alone once browsers revert the historical decision of just shipping a small core language.
hsmyers大约 12 年前
I fear the OP conflates his usage with the rest of the world. Had he presented it as more of a 'this works for me' I'd have paid more attention. My own usage involves things I don't even want to re-invent wheel or no.
conover大约 12 年前
Why not build a tool that takes in a set of JavaScript files, analyzes them, and outputs a stripped down, compressed version of jQuery with only the features used in the input?
评论 #5548063 未加载
tete大约 12 年前
For people that worry about jQuery being to big, there is a lighter replacement for more modern browsers, doing (mostly) the same as jQuery: <a href="http://zeptojs.com/" rel="nofollow">http://zeptojs.com/</a>
评论 #5547938 未加载
tete大约 12 年前
jQuery is used a lot, because it describes a set of features and an interface that many other libraries build upon.
camus大约 12 年前
So now say "death to jQuery" and it makes you look cool trendy right ? or what ? because saying "death to flash" is so 2010 ?<p>I hope you test your code like in 5 desktop browsers with different versions + 4 mobile browers with different versions , what , you dont ? well jQuery devs do ...<p>you dont care ? oh yeah your one of these mobile first , desktop last devs , then good luck with old versions of android browsers ...<p>I'm always amused by all these "death to this" , "death to that" , like it gives anyone any credibility...<p>So you get it folks , dont use jquery , reinvent the wheel like a true purist ,and remember to tell everyone "jQuery must die" , while professionals have code to ship.
评论 #5548078 未加载