If a browser built in jQuery natively, would it speed things up?
-
Say Google built in a native version of jQuery into Chrome or it's Android browser, then made their hosted version of jQuery just return a tiny file if requested from a browser supporting native jQuery (the file might be a single line of js that simply turns on the native one and sets it to the right version). Note that they could easily retract this decision if jQuery falls out of favor, since sites still using it would just fall back to the old behavior. How much of an improvement would this give jQuery sites? I understand that due to caching, the download of the jQuery js files isn't such a big deal, but doing this might save some time to parse the code for each page, and it might make many of the operations faster (such as element selection). It might even make debugging easier, since you wouldn't ever find yourself tracing through jQuery code. And it might make the biggest difference on mobile browsers, where jQuery is still considered a bit of a hog. Overall it just seems like it could be a low-hanging fruit to speed up browser performance. Is there a good reason why browser makers wouldn't do this, considering just how many pages include jQuery? Or would the gains not be significant enough?
-
Answer:
There would definitely be opportunities for browser manufacturers to improve the speed of certain methods if implemented natively, but realistically, the functionality jQuery provides is the way plain ol' JavaScript is going (just with different syntax). For example, one of the most taxing parts of using jQuery is using selectors. JavaScript has increasingly more options for DOM selection as it matures, such as the pretty flexible querySelectorAll(). While this might not support all of the extra pseudo-selectors that jQuery provides, it is way easier to write complex selectors than before. For me, it covers about 100% of the selectors I use in jQuery. Most of the functionality that jQuery provides is already available natively, but jQuery provides a cross-browser promise and some syntactic sugar for its users. When I think about the things that I do most commonly with jQuery, like using selectors, event handling, AJAX, class and other attribute manipulation, style manipulation, and some of the object utilities, these are things that modern JavaScript is perfectly capable of handling on its own. I'm not too sure about the current state of animations in JavaScript besides manipulating the CSS3 properties, but that's probably being worked on as well. (Anyone?) The most compelling reason I can think of for not doing this is versioning. jQuery changes rapidly. I mean, we're already deprecating .live() in favor of the newer delegation method .on(). jQuery is always releasing bug fix releases and performance improvements. So, browsers would have to maintain their optimizations to keep up with newer jQuery ideas. On the developer side, if the browser bundles one version of jQuery, you'll have to detect if the bundled jQuery supports all of the functionality you plan to use, then fallback to including it yourself if it's missing one thing. That's crazy and it really makes it all not worth it. So, the best way going forward, I think, is just to have JavaScript include more and more useful functionality. jQuery can use these additions when available and fall back to its own code when they're not. And which version of jQuery you use as a developer will be totally left to you -- newer changes can be deployed as soon or as slow as you'd like.
Trey Philips at Quora Visit the source
Other answers
It would probably change relatively little, in terms of your overall performance, as you would still need to load jQuery conditionally for all browsers that do not have this magically-native library. As jQuery is just 30k or so minified, many sites include it as a part of their normal script payload, as to minimize http connections. Including this natively would likely cause a number of versioning issues. Those issues aside, for those users using this hypothetical browser, if you're making a separate http call for CDN jQuery, it'll save you about .25s-.5s (depending on connection) on the first page load of a session, after which, it's probably cached.
Matt Ford
What will probably end up happening is the DOM API will just start improving towards the jQuery spec & other great dom libraries. querySelectorAll in the selectors API is a perfect example of how the W3C specs are moving towards a better API.
Stephen Rhyne
I totally agree with Trey Phillips answer, but I think there's larger problems with natively including jQuery: - It can't assumed that everyone prefers or even wants jQuery. - Could there be conflicts with other libraries? - If one library is included, it would open pandora's box to other libraries wanting the same treatment and bloating our fav light and speedy browsers.
Keith Daulton
Related Q & A:
- How to open a partial view from controller as a Jquery Mobile dialog?Best solution by Stack Overflow
- how to add a form with a unique id on jquery?Best solution by Stack Overflow
- What is the maximum speed of a boeing 747? (cruising speed?Best solution by Yahoo! Answers
- What is the difference between a digital TV tuner and a built in TV tuner?Best solution by Yahoo! Answers
- How to clear a browser's cache?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.