Live data from Hacker News

Bling – the $ of jQuery without the jQuery

gist.github.com

51–60 of 138 posts

Re: Bling – the $ of jQuery without the jQuery

#51
post #8

Earlier quoted context omitted.

> to stick with some non-standard helper syntax. Or in other words - replacing an ugly, verbose API with a widely recognised alternate syntax!

Yes "document.querySelectorAll(selector)" is a bit verbose, but jQuery API is no better, do you know what would "$(selector)" actually do? You can't - it depends on what "selector" is.

> "document.querySelectorAll(selector)" is a bit verbose

Right. 35 characters.

> "…but jQuery API is no better"

Your jQuery example is 11 characters.

I can’t believe you’re using verbosity as a measurement, while at the same time claiming 35 and 11 are the same.

Does. Not. Compute.

Re: Bling – the $ of jQuery without the jQuery

#52
post #28
post #18

Can someone explain the new trend to not use jQuery?

A lot of developers originally used jQuery as a cross-browser compatibility library when that was still a major concern. Along the way, jQuery has added tons of extra helper functions and wrappers (ie, .ajax(), .post(), event binding helpers, etc). This has been amazing for web development, but it's also been such a major pillar of web development that a lot of front end developers don't actually know what's happenin…

  > jQuery as a library has now become huge

  > So if you can cut down your cold cache loading times by not
  > including the full jQuery library, that's probably a win
jQuery 1.11.3 is 38.4 KB when minified and gzipped.

jQuery 2.1.4 is 34.1 KB when minified and gzipped.

I'm all for eliminating unnecessary bloat, but it's not as if a jQuery download is a huge amount of data to fetch. While jQuery is not a framework, most front-end JS frameworks are the same size or bigger and don't receive as much attention for being bloated.

If you can get by without jQuery, or if you have a very large number of mobile users and first-load performance is mission-critical for your application, or if you have a large percentage of users from countries with slow or intermittent internet connections, then sure, avoiding jQuery makes sense as a priority. But for most applications, jQuery is a smaller download than a single medium-resolution highly optimized image, and it can be cached forever.

Re: Bling – the $ of jQuery without the jQuery

#53

Earlier quoted context omitted.

Yes "document.querySelectorAll(selector)" is a bit verbose, but jQuery API is no better, do you know what would "$(selector)" actually do? You can't - it depends on what "selector" is.

> "document.querySelectorAll(selector)" is a bit verbose Right. 35 characters. > "…but jQuery API is no better" Your jQuery example is 11 characters. I can’t believe you’re using verbosity as a measurement, while at the same time claiming 35 and 11 are the same. Does. Not. Compute.

Sorry for confusion, what i meant was: yes DOM API is a bit verbose, but jQuery is exactly the opposite in a bad sense: it's using too few words to express too many different things.

Re: Bling – the $ of jQuery without the jQuery

#55

“jQuery is not need anymore with modern browsers.” Bull. Shit. This document proves why, and is written by the same guy that is now pushing this “you don’t want jQuery!” stuff. https://docs.google.com/document/d/1LPaPA30bLUB_publLIMF0Rlh...

So he isn't pushing anything, both things can be valid.

You don't "need" jQuery, but you might not-not need jQuery unless you do something about those bugs.

yell.com mobile site removed jQuery from their codebase, and used that list during the process. Looking at each bug, does it affect them, yes/no. If yes, code around it.

I'm a jQuery fan, but sometimes you might not need jQuery, but sometimes you might not-not need jQuery

Re: Bling – the $ of jQuery without the jQuery

#56
post #28

Earlier quoted context omitted.

A lot of developers originally used jQuery as a cross-browser compatibility library when that was still a major concern. Along the way, jQuery has added tons of extra helper functions and wrappers (ie, .ajax(), .post(), event binding helpers, etc). This has been amazing for web development, but it's also been such a major pillar of web development that a lot of front end developers don't actually know what's happenin…

> jQuery as a library has now become huge > So if you can cut down your cold cache loading times by not > including the full jQuery library, that's probably a win jQuery 1.11.3 is 38.4 KB when minified and gzipped. jQuery 2.1.4 is 34.1 KB when minified and gzipped. I'm all for eliminating unnecessary bloat, but it's not as if a jQuery download is a huge amount of data to fetch. While jQuery is not a framework, most f…

Loading over 30 Kb of minified/gzipped Javascript over a 3G connection on a mobile phone is very problematic, as the bandwidth is poor, the CPU capacity for decompressing and parsing is poorer than on the desktop, so the latency can many times be measured in seconds, therefore loading over 30 Kb of stuff that you don't need gets to be a tough pill to swallow. Also the argument of caching is often brought up, but in my tests this can be very non-deterministic, as mobile phones are pretty aggressive in their used storage. JQuery is supposed to be cached, yet in our A/B testing the load times and consequently the conversion rates improved greatly after we dropped JQuery.

Your comparison with "a single medium-resolution highly optimized image" doesn't hold for mobile phones. On mobile phones users expect latency when loading images, but not when loading the UI. Another problem is that JQuery is not the only commonly used library. You add Underscore, you add Angular, or whatever libraries du-jour we have and pretty soon we are talking about 100 Kb of stuff or even more that is rarely used as a whole.

Of course, my use-case is about having really simple interfaces augmented by Javascript and meant for mobile phones. Well, for complex interfaces I think bringing in JQuery as a dependency may be worth it, but then again, I then start thinking that JQuery is not enough. It's because I want more, I want a virtual DOM that's saner by design, I want to work with immutability, I want much better performance without unpredictable behavior (like what you get with Angular) and I want to only pay for the features I use. JQuery is incompatible with React and is incompatible with Google Closure in advanced mode.

Re: Bling – the $ of jQuery without the jQuery

#57
post #31

I use jquery because I use bootstrap and it requires it for some features I use. I wish that someone would write a drop-in javascript replacement for jquery in the context of bootstrap.

There's zepto.js, which is supposed to be a drop-in replacement for jQuery. Not sure how it fares wrt Bootstrap, though.

It is easy enough to just write a shim. Google "bootstrap zepto shim" to get you started.

Re: Bling – the $ of jQuery without the jQuery

#58
post #23

Earlier quoted context omitted.

> 2) Semicolons are still in debate amongst the JS community, I don't think there's a consensus on whether they're needed or not and it seems to boil down to personal preferences. They are needed. This var func = function(x) { console.log(x); }; func; (42); is different from this var func = function(x) { console.log(x); } func (42)

You're right that your (very contrived) examples are different. But if anybody on my team writes code like this, it doesn't pass code review.

Sure, those examples are quite contrived. Here's one that's not:

  console.log("woof")
  (function() { console.log("foo") })()
Without semi-colons, that blows up (with a super unhelpful error message, to boot). Sure, if you understand ASI in JS, then you'll figure out the problem very quickly. But if you just always use semi-colons, then ASI is one fewer thing to have to worry about.

Re: Bling – the $ of jQuery without the jQuery

#59

Earlier quoted context omitted.

4. Add NodeList.on, which adds the event listener to all nodes in the list

Without the eminently useful support for delegation.

This fork[0] adds delegation.

[0]: https://gist.github.com/MadeByMike/7e7707eff116229a5948

Re: Bling – the $ of jQuery without the jQuery

#60
post #23

Earlier quoted context omitted.

1) Paul Irish is a former jQuery team member and he has blog entries about how much he's learned from reading jQuery's source code, not sure exactly how he's "wrecking jQuery". 2) Semicolons are still in debate amongst the JS community, I don't think there's a consensus on whether they're needed or not and it seems to boil down to personal preferences. 3) This reeks of ad hominem, how exactly is Paul Irish "hipster"?…

> 2) Semicolons are still in debate amongst the JS community, I don't think there's a consensus on whether they're needed or not and it seems to boil down to personal preferences. They are needed. This var func = function(x) { console.log(x); }; func; (42); is different from this var func = function(x) { console.log(x); } func (42)

A very simple rule - if line starts with '[' or '(', put semicolon before. Thats it.

Personally, if all is encapsulated inside self executing function, i put one semicolon before and one after it.

Post reply on HN