Is jQuery Too Big For Mobile?
flippinawesome.org
flippinawesome.org
> Don’t forget that if you’re loading jQuery from a common CDN like Google’s or Microsoft’s, you’re likely introducing zero network latency as the browser will almost certainly have it cached already.
This claim is frequently made, but I’ve also seen many people express skepticism of it. The many different versions of jquery, and several different CDNs, combined with actual typical user behavior patterns, the limited cache capacity of some mobile environments, etc…. it MAY still be true, but I’d really want to see some evidence one way or another before assuming it either way.
It’s not an easy thing to measure though, because we are making claims about “most people’s browsers”, and there’s no easy way to measure other peoples browsers. But is anyone aware of anyone trying to approach it?
Why does it matter? If the "cached in most people's browsers" theory is true, then we would not want to concatenate JQuery into one big JS file (as the OP suggests), and we would not want to customize JQuery to include only the AMD modules actually used (as the OP hints at considering), as either one would prevent cache reuse accross sites.
Me, being skeptical of the theory, I still choose to concatenate (I think it's clearly the way to go), and would consider modular customization in the future if it were more convenient for development workflow or it was for a site where size/speed were an absolute priority.
That said, you also need to be careful with concatenation. It's tempting to go for a 'concatenate everything into one file' approach, but that can be suboptimal. When you've got a large library like jQuery that changes infrequently, concatenating that with your constantly-evolving application code results in your users paying the download cost for jQuery every time you make a change (albeit without the connection overhead). Instead, it make sense for some applications to bundle third party libraries into one file, and the application code into another.
As I said in my original article, the most important thing you can do to improve the performance of your site is to measure client-side performance from your real user traffic, establish a baseline and only then try various techniques and see which ones have the greatest impact for your site and your visitors. There are various techniques that /might/ help, and some are more universal than others, but you won't know for sure if a change helped or hindered if you can't look at your stats.
[1] http://statichtml.com/2011/google-ajax-libraries-caching.htm... [2] http://www.stevesouders.com/blog/2013/03/18/http-archive-jqu...
I have to agree with you. Seeing how my non techy friends use their not high end mobiles, I've decided to go down that road too.
Some of my friends clear cache very frequently, their main point is that images take too much room and this slows device down. Knowing that this is not the case and cheap phones just are slow, they pretty much defeat the whole purpose of cache. I've found that the only way to make web faster for them is to concatenate everything.
FWIW, this is the approach that I use. And I probably care about those pagespeed and yslow numbers probably way more than I should.
This greatly depends on the rest of your content.
In my experience, JQuery is downloaded faster than most analytics tags/logic.
Or your adsl comes down and you find that over the spotty 3g your app suddenly takes 30s+ just to come up with an error message just due to the google fonts you used.
Those two are JUST personal experience in the last 6 months. Last time I brought this up publicly somebody mentioned that most CDN's are blocked in China too.
Given my past experience, I can think of no possible benefit that can make the additional fragility introduced in my systems worthwhile.
I'm not using CDN's for anything more than the odd jsfiddle in the future.
The 4G worst-case scenario is still better than the best-case scenario for a 3G network, which is what you'll see with a majority of users. I'd like to see this analysis done with a 3G connection as well, because I suspect the real jQuery tax for a majority of mobile users is over a second.
I do like the point made about latency and the suggestions at the bottom of the article. It's a strong incentive for apps to introduce a real asset pipeline and js and css minifiers.
The key thing to remember is that your time as a developer should be spent making software that the user will enjoy using - your job is not to make your own life as easy as possible by throwing in libraries with no thought about how it'll affect the user experience. Learn a build tool and use it to optimise your web apps.
Unfortunately, we encountered a lot of bugs, inconsistencies with the jQuery API and general lack of interest in supporting IE. Somewhere halfway through the project we switched to jQuery and we didn't have any performance problems. Some things actually worked better because jQuery has better workarounds for some of the bugs in older Android browsers.
Is "jQuery Mobile" too slow for mobile?
Slow tap performance, slow overall performance, http://www.jquerymobile.com Is "jQuery" too slow for mobile?
Too big, a bit slow. The issue is the compressed file size. It's still huge (81kb) and mobile user will notice if your combined web app JS size goes beyond 200kb (speaking about mobile on Edge network, latency). It also slows down your web app, check out: http://jsperf.com/popular#all-time Do you really need "jQuery" in 2014 on mobile?
I would say no. I have recently coded a 30k HTML5 web app that runs on mobile as fast as native apps. So my advice is to just use native HTML5 JS API, it works fine. Introduction: http://www.sitepoint.com/jquery-vs-raw-javascript-1-dom-form...Edit: added "on mobile" in the last question
If we're talking mobile, then chances are you can do without jQuery. You can almost take for granted that the mobile device has a webkit-based browser. Yes, I say that knowing that there are non-webkit browsers in use and that some browsers are based on older webkit code.
If we're talking about non-mobile users across the spectrum of browsers, I would recommend still using jQuery. It's just too useful in dealing with browser inconsistencies and bugs not to use it.
I could well be adding a bunch of crap to my pages that I don't need. What do proper web devs use for profiling their web sites? To test page size in bytes, amount of JavaScript you've loaded in libs that you don't use, etc.?
> But let’s get back to the numbers. Per the data above, a typical user on an average device and network will take ~50ms to download jQuery and another ~250ms to parse it.
An average delay of 300ms is simply unacceptable. I have a hard time believing that 50ms to download jQuery is average, so I assume that the author isn't including round-trip time.
To be fair, this is also from the article:
> And in my opinion, the painfully slow parsing and interpretation of scripts on mobile browsers – particularly older Android ones – is the only compelling reason to prefer tiny JavaScript libraries.
It's the author's opinion that this is the only compelling reason, but it is a VERY compelling reason.
Even with a initial congestion window of 10 segments there's going to be at least two round trips, if the window is smaller then it's going to me more.
Using devtools on my office network connection it takes 1.3s to download jQuery from the site with the post
Having that said, the problem isn't that jQuery is too big for mobile. Lots of things incur a largish download size for mobile. Bootstrap's ginormous CSS bundle first comes to mind. The biggest headache with jQuery on mobile is that it's too damn slow in execution. On a tablet where you have tons of screen space to display lots of widgets, creating largish amount (> 200) jQuery contexts can easily kill your frame rate to something < 10fps.
I understand that as a dev you definitely want your JS in separate files for practical reasons, but couldn't you just have separate .js files and have your framework stick them inline "at runtime"?
PS: Is there any talk with HTTP 2.0 of allowing data like images to be somehow "inlined"? It would then be possible to serve up a 21st century website with a single RTT, right
Of course, that also needs a properly configured server (a very large number of sites out there don't see proper client caching so the browser still need to ask the server if the file has changed every single time, for example).
The real issue is design decisions, jq's not incredibly light, but at least there is some real value in it.
Those numbers on avg web page size and rts are atrocious, people should be ashamed of themselves.
https://developers.google.com/closure/compiler/docs/api-tuto...
tldr: The reason people pull it as an extern is because it does not work with advanced optimisations.
Disclosure: I'm rebuilding a pretty big BackboneJS app (which I started building two years ago with a team that grew to two dozen people) into an AngularJS-based mobile webapp.
Note also that AngularJS is a whopping 700 KB before minification and gzipping (270 KB minified/gzipped).
Here is the file http://code.angularjs.org/1.2.14/angular.min.js And here you can get the gzipped size http://closure-compiler.appspot.com/home