3 ms·
>If all you are doing is making HTML elements, DO NOT USE JQUERY. That's pure premature optimization. I don't understand how people can still be making blanket
by mistercow 14y ago
>If all you are doing is making HTML elements, DO NOT USE JQUERY.
That's pure premature optimization. I don't understand how people can still be making blanket statements about performance costs like this. Using jQuery to create HTML elements is fine. It's convenient and succinct, and it keeps your code consistent. Otherwise, you'll have two ways of creating HTML elements: one for when you are just creating an element, and another for when you need to use jQuery on it afterward.
But if you do hit a point where creating HTML elements with jQuery is slow, you optimize that point and leave a comment explaining why you're doing it that way.
People get these ideas in their heads that somehow they're going to be able to code everything super fast from the very start, and it's nonsense. All you're going to do is make it harder to maintain your project.
- MatthewPhillips 14y agoThe types of optimizations you are suggesting are extremely hard to track down. If you have a laggy list you only know that you have a laggy list.. changing a single $('<div></div>') to document.createElement('div') probably isn't the thing that will speed up your application. It's probably not a single function or even a set of functions that is causing the problem. It's probably that in order to gain the 'sticky' affect you want that jquery plugin you're using is listening to a window.onscroll or something, and unless you want to dig into the code of every library you're using you probably won't know why. When you're working in the mobile web and performance is important you want to know what every line of code is doing. Your application is probably going to be a little laggy anyways, but at least you'll know why that is and know where to target to try and fix it.
- mistercow 14y ago>The types of optimizations you are suggesting are extremely hard to track down Except that it's not, because you can use profiling in modern browsers to figure out where the time is being spent. >It's probably that in order to gain the 'sticky' affect you want that jquery plugin you're using is listening to a window.onscroll or something, and unless you want to dig into the code of every library you're using you probably won't know why. But that's not what the author is arguing, and it has nothing to do with adding elements to the DOM via jQuery vs via lower level methods.