r/programming • • Jun 09 '16

jQuery 3.0 Released!

https://blog.jquery.com/2016/06/09/jquery-3-0-final-released/
1.1k Upvotes

354 comments sorted by

View all comments

Show parent comments

128

u/EternalNY1 Jun 10 '16 edited Jun 10 '16

As IE11 becomes the trailing edge browser we need to support, the need for jQuery shrinks to zero.

Not true, because they can slim down jQuery (as you see with 3.0) which still allows you to turn what might be 20 lines of ECMA-compliant JavaScript into a one-liner that even assures you much better compatibility.

It's still useful, as long as it's not bloated, and fast.

It makes your own code more readable ... the whole "DRY principle".

This?

var d = document.getElementsByClassName("goodbye");
var i; 
for (i = 0; i < d.length; i++) { 
  d[i].className = d[i].className + " selected";
}

Or?

$(".goodbye").addClass("selected");

52

u/stns_da_mnns Jun 10 '16

Someone who gets it! There are far worse things to do than include jQuery to make your webpage slower. Who needs 4K images on a focking phone?

61

u/EternalNY1 Jun 10 '16 edited Jun 10 '16

Yes. I try to explain it, people don't get it.

And by "people" I mean "developers" which makes it even more frightening.

Sadly, as a senior developer I've had to lay people off after I asked them, politely, numerous times to please stop trying to squeeze out the extra 15 milliseconds of some function that runs once a day and focus on the real problems on the list.

And not "Lumberg" politely ... just trying to explain that it is not a priority and we have bigger problems. It sucked. But soooo many people do this.

Because if you can shave it from 30 ms to 15 ms ... that's twice as fast. To the one person who might run it, once a day.

"But you have to pull in the whole library!".

Yes, well your logo in the top left corner is twice the size of jQuery and could be 100 times smaller and look the same.

Oh, and jQuery wasn't actually downloaded as you can see in the developer tools network panel ... it's cached on almost everyone's machine.

25

u/[deleted] Jun 10 '16

The three things you don't bring up at the dinner table: religion, politics, and jQuery.

6

u/vplatt Jun 10 '16

Wait... you said religion twice!

1

u/tuxayo Jun 10 '16

Does anyone have an idea of the time to parse/load/process jQuery compared to the time to process an over-sized image?

To know is these are relevant compared to the download time.

2

u/EternalNY1 Jun 10 '16

You can benchmark it yourself in the dev tools of whatever browser you want. This is not a hard number because it depends on the client browser, that browser's JS engine, and the client specs.

However, from the release notes, they are reducing this even further.

For the record, I think this is stupid too. Because now we're saving 7k for a version that might not be cached. Why not just stick with the regular 30k one which will likely transfer 0 bytes?

If you switch to the "Slim Build" then your server is going to be sending out 23.6k instead of 0k because it may not be cached.

Slim Build - Finally, we’ve added something new to this release.

Sometimes you don’t need ajax, or you prefer to use one of the many standalone libraries that focus on ajax requests.

And often it is simpler to use a combination of CSS and class manipulation for all your web animations.

Along with the regular version of jQuery that includes the ajax and effects modules, we’re releasing a “slim” version that excludes these modules.

All in all, it excludes ajax, effects, and currently deprecated code.

The size of jQuery is very rarely a load performance concern these days, but the slim build is about 6k gzipped bytes smaller than the regular version – 23.6k vs 30k.

1

u/tuxayo Jun 11 '16

Why not just stick with the regular 30k one which will likely transfer 0 bytes?

Did someone measured the actual cache hit rate when browsing many websites? Because if the deployed versions are too various or not using the same CDN, then the caching argument would be overestimated.

Because now we're saving 7k for a version that might not be cached.

Why would it be not cached compared to the previous releases?

1

u/EternalNY1 Jun 11 '16

Did someone measured the actual cache hit rate when browsing many websites? Because if the deployed versions are too various or not using the same CDN, then the caching argument would be overestimated.

[MaxCDN says "We usually average around 15,000 hits per second to our CDN with 99.8% of those being cache hits."] (https://news.ycombinator.com/item?id=9866697)

Why would it be not cached compared to the previous releases?

It would be, but it's "yet another thing to cache", for 7k bytes?

CDN JS Usage Statistics

jQuery CDN Usage Statistics

1

u/tuxayo Jun 12 '16

MaxCDN says "We usually average around 15,000 hits per second to our CDN with 99.8% of those being cache hits."

I was referring to browser cache hits. The link particularly insists on the fact that those 99.8% are not browser cache hits.

Why would it be not cached compared to the previous releases?

It would be, but it's "yet another thing to cache", for 7k bytes?

Right, that would lower the hit rate.

→ More replies (2)

12

u/puhnitor Jun 10 '16 edited Jun 10 '16
[...document.querySelectorAll('.goodbye')].forEach(goodbye => goodbye.classList.add('selected'));

80

u/EternalNY1 Jun 10 '16

forEach

Yes if you want all versions of IE dropped as well as Safari.

Or bring in jQuery, small and fast and almost guaranteed to be cached locally anyway, and get it fully compatible in 1 (shorter) line without the lambda "arrow function".

So, in your case, we'd have (works on some browsers):

[...(document.querySelectorAll('.goodbye')].forEach(goodbye => goodbye.classList.add('selected'));

Works on almost all browsers:

$(".goodbye").addClass("selected");

15

u/Elsimir Jun 10 '16

forEach is the least of the compatibility problems there too, there's a spread operator and an arrow function.

6

u/EternalNY1 Jun 10 '16

Was trying to keep it simple :)

1

u/jacobrask Jun 10 '16

jQuery, small and fast and almost guaranteed to be cached locally

That you keep claiming this in every comment does not make it any more true. There is a huge fragmentation in jQuery versions, so even if 100% of all jQuery sources were served from the same CDN the chance of them having your particular version cached is not great. See https://www.stevesouders.com/blog/2013/03/18/http-archive-jquery/

2

u/EternalNY1 Jun 10 '16

That you keep claiming this in every comment does not make it any more true.

Where's that little emoticon with the smiley smashing his head against the wall? :)

Ok, no problem.

There's only one real way to answer this question, and since I don't work in your office ....

What percentage of your bandwidth utilization from the server is currently being taken up by serving jQuery?

Almost no one can answer that, and that is the problem. I can answer it, I know down to a single byte how much the server is sending out jQuery as opposed to the thousands of other things in a given request.

People spend all day worrying about "all these bytes being sent" when they are not looking at the numbers.

If you have the numbers, then you don't even need to be posting this, because you understand what you're doing, as do I.

→ More replies (35)

10

u/thebuccaneersden Jun 10 '16

that... that does not look as clean... just sayin...

24

u/EternalNY1 Jun 10 '16
  • Not as clean

  • Not as compatible

All fixed in a 34kb lib that likely will not even be downloaded because the client already has it.

4

u/earthboundkid Jun 10 '16

That's flashy, but even just querySelector basically does the hard part that jQuery used to do.

2

u/vplatt Jun 10 '16

Boo! Hiss!

2

u/puhnitor Jun 10 '16

VanillaJS is the best framework.

18

u/vplatt Jun 10 '16

I understand what you're saying, but if I have to choose between:

$(".goodbye").addClass("selected");

And:

[...document.querySelectorAll('.goodbye')].forEach(goodbye => goodbye.classList.add('selected'));

It's not much of a contest.

1

u/[deleted] Jun 10 '16

Meh, that works, but something like the bind syntax which is in proposal stage looks a lot cleaner.

→ More replies (50)