![]() getElementByID() method, rather than using its own selection engine. Selecting by ID is much faster than selecting by class, since jQuery just wraps around the native. You can speed up jQuery’s selection by using IDs over classes wherever possible. The $ in front of the variable is convention for naming jQuery object variables, and isn’t required. This prevents jQuery from running multiple searches every time you use the $() syntax to find an element. If you’re referencing an item multiple times, cache it in a variable: var $item = $('#item') In fact, doing anything with the DOM is slow, so you’ll want to minimize the DOM related calls in your scripts. Most of the added time comes from the delay at the end of the loop before the next one starts, so loops with a small amount of code and long length will see a greater performance hit than loops with a lot of code and a few elements. They’re both fast, but each is much slower, despite being much more readable. Use for loops rather than jQuery’s each loops whenever you’re looping over a significant number of items. ![]() Having too many laggy function calls can drop your app’s framerate below the refresh rate, which will feel like janky microstuttering to the end user, or just straight up lag. jQuery is still very fast, but you’ll want to watch for unoptimized code. Since jQuery wraps around native Javascript functions, it will always be less performant than using vanilla JS, with the tradeoff being that it speeds up development time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |