jQuery Performance
jQuery is fast for most use cases but can slow pages if used carelessly. Key areas: DOM queries, animation, AJAX, event binding, and object creation.
jQuery is fast for most use cases but can slow pages if used carelessly. Key areas: DOM queries, animation, AJAX, event binding, and object creation.
// Performance anti-patterns
$(".item").css("color", "red"); // OK
// Bad: repeated DOM query in loop
for (let i = 0; i < 100; i++) { $(".list").append("<li>" + i + "</li>"); }
// Better: cache + build string
const $list = $(".list");
let html = "";
for (let i = 0; i < 100; i++) { html += `<li>${i}</li>`; }
$list.html(html);
Every $() call queries the DOM — cache the result if you use it more than once.