Hacker News new | ask | show | jobs
by Warry 5554 days ago
Hi!

I had to leave earlier ParisJS, so I haven't seen your presentation, but people have given me some nice feedbacks! I like the way you take care of performance, it's cool!

But... I'm not sure that caching your result is a good idea. Almost by definition, Javascript is changing the DOM, so are the results eventually. A good practice is to cache-it, but manually is good enough, and at least you keep the power on the lists. I mention this because this is the feature you've highlighted with your benchmark.

Here an explanation of my words :

scope.ready(function(my, $) {

$("h2").addClass("mytest");

$("div").appendHtml("<h2>Test</h2>");

$("h2").addClass("mytest2");

});

>>> My new h2 doesn't have any class.

I'm looking forward to see how this will evolve! Keep going!

1 comments

In my.js, elts wrappers are both cached by id and in their native HTMLElements. The performance increases are sometimes from 1 to 100. Caching FTW. In fact, caching has only 1 minor fallback: you can't change an elt id if you have already accessed it by his former id (but who does? it's such bad practice). For the above snippet, it's normal that your new h2 doesn't have any class since the $ fn only returns the first h2 (like querySelector) contrary to jQuery $ who returns a set. The 3rd line of your code only add class to your first h2. To get a set of selected elts in my.js, use "$.elts" and it will work! If you're interested, I may give a presentation on my.js at the next WebWorkerCamp in Paris!