News for hackers. Stuff that matters.
Re:90% Good parts of jQuery - at only 13% of the size by numlocked on Saturday November 19, 2011 @07:17PM (#3256780)
Don't most apps reference jQuery from a CDN source (like Google)? In those cases jQuery is probably served from the browser cache. And if "those cases" are "most cases", is having a smaller version of a similar library particularly valuable?
Re:90% Good parts of jQuery - at only 13% of the size by pamelafox on Saturday November 19, 2011 @07:31PM (#3256813)
The parse time is significant for jQuery, atleast on some mobile devices. For example, in my tests on an Android N1 today, jQuery took 800ms to parse (even when cached) whilst Zepto took 300ms -- saving 500ms.
Re:90% Good parts of jQuery - at only 13% of the size by DiabloD3 on Saturday November 19, 2011 @07:36PM (#3256834)
Google in their Page Speed ranking consider 100kb == 100ms.

See: https://code.google.com/speed/page-speed/docs/mobile.html#De...

BTW, their Page Speed thing is now available online: https://developers.google.com/pagespeed/

Re:90% Good parts of jQuery - at only 13% of the size by agentgt on Sunday November 20, 2011 @09:09AM (#3258118)
I wonder if there is any better optimization that browsers can do for this (like at least cache the AST if the exact same JS is loaded).
Re:90% Good parts of jQuery - at only 13% of the size by dextorious on Sunday November 20, 2011 @03:30AM (#3257628)
Parent talks about parsing speed.
Re:90% Good parts of jQuery - at only 13% of the size by DiabloD3 on Sunday November 20, 2011 @01:22PM (#3258629)
So does Google.
Re:90% Good parts of jQuery - at only 13% of the size by numlocked on Saturday November 19, 2011 @07:34PM (#3256825)
Interesting. Is parse time generally a function of code length, or overall complexity/CPU time?
Re:90% Good parts of jQuery - at only 13% of the size by pamelafox on Saturday November 19, 2011 @07:42PM (#3256849)
(I'm not an expert) but it's more than simply code length - it also depends on if the library runs any functions at parse time, and perhaps also how many variables it puts in the global space.

For example: I discovered that my tiny localStorage library was taking 300ms to load, and that was because I was doing feature detection at parse-time and that feature detection attempted to actually set an item in localStorage. I postponed that, and got the load time down to 20ms.

Re:90% Good parts of jQuery - at only 13% of the size by ruethewhirled on Sunday November 20, 2011 @02:54PM (#3258855)
Do you mind sharing what are you using/doing to benchmark that? cheers
Re:90% Good parts of jQuery - at only 13% of the size by tfb on Saturday November 19, 2011 @07:33PM (#3256820)
I'm considering using it because of a combination of the following:

1) You can't always count on users having cached it from the CDN.

2) If it's included on my own server I can be sure they're getting exactly what I intend and there will be less HTTP requests when I include it with the rest of my JS which will only add ~4kb.

3) I'm a bit of a minimalist when it comes to code - for the web at least.

Re:90% Good parts of jQuery - at only 13% of the size by wisty on Saturday November 19, 2011 @10:33PM (#3257173)
For small libraries, and users with fast connections, the HTTP request can be the limiting factor.
Re:90% Good parts of jQuery - at only 13% of the size by tfb on Wednesday November 23, 2011 @10:40AM (#3270346)
The idea is to include all javascript in a single HTTP request. Sorry if that wasn't clear in point #2.
Re:90% Good parts of jQuery - at only 13% of the size by dextorious on Sunday November 20, 2011 @03:32AM (#3257631)
"""1) You can't always count on users having cached it from the CDN."""

No, but you can always count the MAJORITY of users will have it cached from the CDN.

Re:90% Good parts of jQuery - at only 13% of the size by spjwebster on Sunday November 20, 2011 @07:22AM (#3257951)
You need to be careful with your wording here. The "MAJORITY" of the top 1m websites (based on Alexa rankings) don't use Google's CDNs (i.e. load a resource from googleapis.com):

http://httparchive.org/trends.php#perGlibs

...and that's across all versions of all libraries.

Quite how that correlates with how many of your first-time visitors will already have the library cached – because they happen to have recently visited another site that uses the same version of the same library – depends on how much your visitor demographic intersects with those sites that use the CDN. You then need to offset that against the DNS lookup time requires for the rest of your visitors to work out whether loading the file from Google's CDN makes sense.

If you're talking about repeat visitors, it doesn't matter where the file was served from, so long as you apply the correct cache-controlling headers.

Re:90% Good parts of jQuery - at only 13% of the size by dextorious on Sunday November 20, 2011 @08:07AM (#3258018)
17% of the top million sites using them (and rising) is like a guarantee the user will have it. It's not like they reset their browser cache every few days. Also, if their ISP does caching, it will most definitely be there too.

Besides, even when they don't have it, Google's CDN is better than a hit on your servers, both for your IO load, parallelism, delivery speed, etc.

Re:90% Good parts of jQuery - at only 13% of the size by simonw on Sunday November 20, 2011 @10:58AM (#3258320)
Yahoo found that 40-60% of users were hitting the site with an empty cache at least once per day: http://www.stevesouders.com/blog/2010/04/26/call-to-improve-...
Re:90% Good parts of jQuery - at only 13% of the size by youngtaff on Sunday November 20, 2011 @11:29AM (#3258392)
There's some research around suggesting that with so many versions of jQuery in use that the chances of finding the version of jQuery your site uses in cache is quite small. (can't find the article at the moment)

Components don't seem to stay in cache for very long these days because browser caches are max only 50MB (phones are much smaller) and with a bit of surfing it's easy to get to a position where components get ejected.

Also there is no guarantee that retrieving it from Google's CDN is faster than retrieving it from your servers e.g. there's DNS resolution, TCP connections to be setup etc., some of which will already be done for the main site.

Re:90% Good parts of jQuery - at only 13% of the size by spjwebster on Sunday November 20, 2011 @05:18PM (#3259170)
I've just run my own analysis on the HTTP Archive data, and the fragmentation issues are very real. The most popular URL used to load jQuery was:

http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min...

...and it was used by just 2.7% (945) of the 35,204 pages in the dataset. Note that it's not just version fragmentation - you have to take protocol into account too as browsers cache HTTP and HTTPS separately.

The next most popular was:

http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min...

...used by 1.3% (460) of pages, followed by:

http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min...

...used by 0.8% (285) of pages.

At this point there really isn't much of a debate; unless you have evidence to the contrary (e.g. all our visitors come from Facebook, and Facebook use the same version of jQuery as we do) using Google's CDN to load jQuery isn't likely to benefit the majority of your first-time visitors.

Re:90% Good parts of jQuery - at only 13% of the size by spjwebster on Monday November 21, 2011 @10:10AM (#3261323)
For those interested, I delved a little further and wrote up my findings here:

http://statichtml.com/2011/google-ajax-libraries-caching.htm...

Re:90% Good parts of jQuery - at only 13% of the size by jaredstenquist on Sunday November 20, 2011 @12:04AM (#3257322)
Even though the Google Jquery libraries are used by a large number of top 100 sites, I prefer to serve my own files. 100k or 200k for the foundation of functionality that jquery provides isn't going to severely affect your visitors in any way.

Of course I'm assuming you're using common best practices with cache-control/expires headers.

Re:90% Good parts of jQuery - at only 13% of the size by DiabloD3 on Saturday November 19, 2011 @07:33PM (#3256822)
No, a lot of HTTPS sites won't because its a security hazard and also requires a CDN that provides HTTPS as well.
Re:90% Good parts of jQuery - at only 13% of the size by rsoto on Saturday November 19, 2011 @07:46PM (#3256854)
...Which those CDN provide support as well: https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
Re:90% Good parts of jQuery - at only 13% of the size by ufo on Saturday November 19, 2011 @09:58PM (#3257112)
...but is it really worth it to give Google a "backdoor" into your https app just because you want to load jQuery faster?
Re:90% Good parts of jQuery - at only 13% of the size by icebraining on Saturday November 19, 2011 @10:41PM (#3257189)
I find it very improbably that Google will decide to mess with it, but as a general feature it would be nice if one could indicate an hash of the file to be loaded (as a <script> attribute), and throw an error callback if the verification failed.

That way you could use Google's jQuery file without being vulnerable to them messing with the file contents.

Re:90% Good parts of jQuery - at only 13% of the size by mythz on Saturday November 19, 2011 @11:46PM (#3257297)
I'd say there is 0.000% chance google would use it's CDN to compromise 3rd party sites. It would be discovered in a flash and in no way will it every justify the brand confidence hurt.
Re:90% Good parts of jQuery - at only 13% of the size by X-Istence on Saturday November 19, 2011 @10:38PM (#3257186)
The user most likely already is giving Google a backdoor into your app ... if they are using Chrome.
Re:90% Good parts of jQuery - at only 13% of the size by drivebyacct2 on Saturday November 19, 2011 @10:41PM (#3257190)
What? That's absurd. You understand why that is hyperbolic, right?
Re:90% Good parts of jQuery - at only 13% of the size by X-Istence on Sunday November 20, 2011 @12:47AM (#3257391)
Just as absurd as Google destroying any and all confidence any of us tech people would have in them as a company if they loaded malicious javascript instead of jquery or along with jquery from their CDN's.

That is the point I was trying to make.

Re:90% Good parts of jQuery - at only 13% of the size by drivebyacct2 on Sunday November 20, 2011 @01:50AM (#3257497)
My apologies. I understand and think you make a very good point.
Re:90% Good parts of jQuery - at only 13% of the size by yuhong on Sunday November 20, 2011 @02:29AM (#3257539)
It is not just Google. Anyone that can get a fake certificate issued by a trusted CA for ajax.googleapis.com can MITM it and do the backdoor.
Re:90% Good parts of jQuery - at only 13% of the size by waitwhat on Sunday November 20, 2011 @08:20AM (#3258033)
That's not as universally true as it used to be. Chrome has introduced certificate-pinning [1] which covers googleapis.com [2].

[1] http://www.imperialviolet.org/2011/05/04/pinning.html

[2] http://src.chromium.org/viewvc/chrome/trunk/src/net/base/tra...