Improving performance re-using selected elements (Become an expert)
In this recipe, we'll see how we can store a collection of previously selected elements in a variable for a later processing and how this method can improve performance.
How to do it...
This time our goal will be a little different. Instead of applying margins or borders, we'll perform a comparison to show how in a (simulation of a) real-world page, caching objects can significantly improve performance. In order to understand the explanation, follow these steps:
- Create a copy of the
template.html
file and rename it asreusing-elements.html
. - Edit the
<head>
section of the page adding this code:<script> $(document).ready(function() { var start = new Date(); var $description = $('.description'); ...
Get Instant JQuery Selectors now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.