Live data from Hacker News

Vanilla JS, fast, lightweight, cross-platform framework

vanilla-js.com

91–100 of 134 posts

Re: Vanilla JS, fast, lightweight, cross-platform framework

#91
post #75

Given how optimized jquery is, does anyone understand why something as simple as getting an element by id would be so much slower than Dom methods?

I'm surprised by the number of comments like this. jQuery has to parse the selector and figure out that it's of the form "#id". This requires running a regular expression. A lot more is happening. The whole jQuery call from start to finish takes 2.85 microseconds, in what is presumably a real benchmark, but microbenchmarks like this are hard to interpret and basically meaningless. But yes, if your app needs to do a b…

> I'm surprised by the number of comments like this.

The sentiment is borne out by the facts when you dig a little deeper. Just calling document.getElementById without using the return value does not actually dig into the DOM and find the element according to this comment: http://news.ycombinator.com/item?id=4436438

Re: Vanilla JS, fast, lightweight, cross-platform framework

#92
post #18

Earlier quoted context omitted.

I'll take $('p').text('Hello.') over for (var p in document.getElementsByTagName('p')) { p.innerHTML = 'Hello.'; } any day!

innerHTML is an easy one, try setting an attribute -- you have to create a new attribute node, set its value and then add that to the element..

You should set the node property instead (e.g. standard textContent or innerText). It will work everywhere.

Re: Vanilla JS, fast, lightweight, cross-platform framework

#93
post #45

Earlier quoted context omitted.

Premature optimization, and all that. It is trivial to get raw dom nodes out of jQuery, so you can easily use jQuery to begin with and replace any code with the full DOM API calls should it every become a performance issue. This discussion is a bit like how assembly programmers used to defend not moving to a high level language long after the performance benefits were not worth it any more.

> This discussion is a bit like how assembly programmers used to defend not moving to a high level language long after the performance benefits were not worth it any more. But we're not at that point in the web yet. The performance benefits are worth it. Just try out JQuery Mobile if you want to see what wasted CPU cycles can do.

It may be worth it for specific use cases, just like there are certainly still specific use cases where assembly shines.

The point is we're well past the point where grasping for the asm-equivalent from the start should be the default unless you happen to specifically target one of those niches.

Re: Vanilla JS, fast, lightweight, cross-platform framework

#94
post #93

Earlier quoted context omitted.

> This discussion is a bit like how assembly programmers used to defend not moving to a high level language long after the performance benefits were not worth it any more. But we're not at that point in the web yet. The performance benefits are worth it. Just try out JQuery Mobile if you want to see what wasted CPU cycles can do.

It may be worth it for specific use cases, just like there are certainly still specific use cases where assembly shines. The point is we're well past the point where grasping for the asm-equivalent from the start should be the default unless you happen to specifically target one of those niches.

Mobile isn't a niche.

Re: Vanilla JS, fast, lightweight, cross-platform framework

#95
post #29
post #18

Earlier quoted context omitted.

I'll take $('p').text('Hello.') over for (var p in document.getElementsByTagName('p')) { p.innerHTML = 'Hello.'; } any day!

This enumeration is done the wrong way. You enumerate over a DOM node list which looks like an array, which includes enumerable properties like "length". This means that the variable "p" at some point will be "length" and "length".innerHTML = "..." will produce an error. The proper way is: for( var i=0, ps=document.getElementsByTagName('p'), len=ps.length; i < len; i++) {ps[i].innerHTML = 'Hello.';}

Ah, thanks for the correction! I just wrote it out from memory, and it's been a while since I used Vanilla-JS DOM selectors ;)

Re: Vanilla JS, fast, lightweight, cross-platform framework

#96
post #57

Earlier quoted context omitted.

Aren't the polyfills pretty good nowadays?

Yes, but using all of them needed for full HTML5 support in, say, IE6, probably takes up more bandwidth than downloading a new browser.

Most people using IE6 are doing so because they can't download a new browser e.g. ActiveX support or lockdown corporate machine.

Re: Vanilla JS, fast, lightweight, cross-platform framework

#97

Earlier quoted context omitted.

jQuery is kind of a big download for mobile, so I often skip it for small tasks. What gets me is when people include jQuery and then further bog things down by loading a lot of plug-ins to do things that could easily be accomplished by adding a few lines of code of their own. Even if you do need and include jQuery, it doesn't mean you have to use it for every piece of javascript in your app. Many times, a plug-in wil…

> jQuery is kind of a big download for mobile, so I often skip it for small tasks. That's what Zepto[0] is for: jQuery's API, 20% of the size (although it drops some features, e.g. $(selector) is pretty directly proxied to document.querySelectorAll, so $('> .foo') works in jQuery but blows up in Zepto) [0] http://zeptojs.com/

Ah, last I looked at Zepto, it's support for non-webkit browsers was pretty lacking. It's good to see they're making strides on the cross-platform comparability front. The supported browsers list looks pretty good now.

Re: Vanilla JS, fast, lightweight, cross-platform framework

#98
post #68

Earlier quoted context omitted.

And what's IE10s market percentage? Less than a fraction of a fraction of a percent I bet. And with current reviews of Win8, I don't see that changing in a meaningful way for soooome time.

I think you missed the announcement where Microsoft is going to do a silent update of IE10 to consumer PC's. IE9 usage will drop to the low single digits within a year and IE10 will take its place as the leading IE browser.

What about IE8? That's still well above 10% I think.

Re: Vanilla JS, fast, lightweight, cross-platform framework

#99
post #93

Earlier quoted context omitted.

It may be worth it for specific use cases, just like there are certainly still specific use cases where assembly shines. The point is we're well past the point where grasping for the asm-equivalent from the start should be the default unless you happen to specifically target one of those niches.

Mobile isn't a niche.

That depends on the application.

Re: Vanilla JS, fast, lightweight, cross-platform framework

#100
post #32
post #21

Earlier quoted context omitted.

did you ever try to debug your pretty jquery karate? ps. second example is not valid, in Vanilla JS you do it like this: document.getElementsByTagName('p').filter(function(el) { el.innerHTML = 'Hello.'; });

The right way is this :) Array.prototype.forEach.call(document.getElementsByTagName('p'), function(el) { el.innerHTML = 'Hello.'; });

I like how the end of that statement contains both a winking crooked-smile smiley next to black-eyed frown smiley.
Post reply on HN