Stop Using getBoundingClientRect() in Loops. It’s Killing Your Performance.

📰 Medium · JavaScript

Learn why using getBoundingClientRect() in loops can severely impact performance and how to optimize it

intermediate Published 21 Apr 2026
Action Steps
  1. Avoid using getBoundingClientRect() in loops to prevent layout thrashing
  2. Use caching or memoization to store the results of getBoundingClientRect()
  3. Consider using alternative methods such as getClientRects() or DOMRect
  4. Optimize your code by reducing the number of DOM reads and writes
  5. Test and profile your code to identify performance bottlenecks
Who Needs to Know This

Frontend developers and engineers can benefit from this knowledge to improve the performance of their web applications

Key Insight

💡 getBoundingClientRect() can cause layout thrashing and severely impact performance when used in loops

Share This
🚨 Using getBoundingClientRect() in loops can kill your performance! 🚨 Learn how to optimize it and improve your web app's speed

Key Takeaways

Learn why using getBoundingClientRect() in loops can severely impact performance and how to optimize it

Full Article

Title: Stop Using getBoundingClientRect() in Loops. It’s Killing Your Performance.

URL Source: https://medium.com/@laxmiphalak/stop-using-getboundingclientrect-in-loops-its-killing-your-performance-4610f178877f?source=rss------javascript-5

Published Time: 2026-04-21T16:07:46Z

Markdown Content:
# Stop Using getBoundingClientRect() in Loops. It’s Killing Your Performance. | by Laxmi Phalak | Apr, 2026 | Medium

[Sitemap](https://medium.com/sitemap/sitemap.xml)

[Open in app](https://play.google.com/store/apps/details?id=com.medium.reader&referrer=utm_source%3DmobileNavBar&source=post_page---top_nav_layout_nav-----------------------------------------)

Sign up

[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40laxmiphalak%2Fstop-using-getboundingclientrect-in-loops-its-killing-your-performance-4610f178877f&source=post_page---top_nav_layout_nav-----------------------global_nav------------------)

[](https://medium.com/?source=post_page---top_nav_layout_nav-----------------------------------------)

Get app

[Write](https://medium.com/m/signin?operation=register&redirect=https%3A%2F%2Fmedium.com%2Fnew-story&source=---top_nav_layout_nav-----------------------new_post_topnav------------------)

[Search](https://medium.com/search?source=post_page---top_nav_layout_nav-----------------------------------------)

Sign up

[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40laxmiphalak%2Fstop-using-getboundingclientrect-in-loops-its-killing-your-performance-4610f178877f&source=post_page---top_nav_layout_nav-----------------------global_nav------------------)

![Image 1](https://miro.medium.com/v2/resize:fill:64:64/1*dmbNkD5D-u45r44go_cf0g.png)

# Stop Using `getBoundingClientRect()` in Loops. It’s Killing Your Performance.

## Meet Pretext — the library changing how we build feeds, chat apps, and dynamic layouts without layout thrashing or DOM reads

[![Image 2: Laxmi Phalak](https://miro.medium.com/v2/resize:fill:64:64/1*iHAS0LEj3sbPhfO4l5CD4Q.png)](https://medium.com/@laxmiphalak?source=post_page---byline--4610f178877f---------------------------------------)

[Laxmi Phalak](https://medium.com/@laxmiphalak?source=post_page---byline--4610f178877f---------------------------------------)

5 min read

·

Just now

[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fvote%2Fp%2F4610f178877f&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40laxmiphalak%2Fstop-using-getboundingclientrect-in-loops-its-killing-your-performance-4610f178877f&user=Laxmi+Phalak&userId=6459693d60cf&source=---header_actions--4610f178877f---------------------clap_footer------------------)

--

[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fbookmark%2Fp%2F4610f178877f&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40laxmiphalak%2Fstop-using-getboundingclientrect-in-loops-its-killing-your-performance-4610f178877f&source=---header_actions--4610f178877f---------------------bookmark_footer------------------)

[Listen](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2Fplans%3Fdimension%3Dpost_audio_button%26postId%3D4610f178877f&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40laxmiphalak%2Fstop-using-getboundingclientrect-in-loops-its-killing-your-performance-4610f178877f&source=---header_actions--4610f178877f---------------------post_audio_button------------------)

Share

Press enter or click to view image in full size

![Image 3](https://medium.com/@laxmiphalak/stop-using-getboundingclientrect-in-loops-its-killing-your-performance-4610f178877f?source=rss------javascript-5)

_Not a member? (_[_Read for free here_](https://medium.com/@laxmiphalak/4610f178877f?sk=d69568f2beffb0eb62b20c7f02d3065e)_)_

Every time your JavaScript asks the browser: “_how tall is this text”_? The browser doesn’t just give you a number. It **stops everything**, recomputes your _entire page_ layout, and _then_ answers.

One questi
Read full article → ← Back to Reads

Related Videos

How to Use Semrush Keyword Magic Tool with ChatGPT to Make Money
How to Use Semrush Keyword Magic Tool with ChatGPT to Make Money
Grow with Will - SEO, Sales & Entrepreneurship
How To Build A Twitter Clone - React Next JS - Appwrite Crash Course
How To Build A Twitter Clone - React Next JS - Appwrite Crash Course
Adrian Twarog
The FASTEST Way To Learn Webflow (Quick-Start Guide)
The FASTEST Way To Learn Webflow (Quick-Start Guide)
Alex Leischow
Elementor Angie Ai Plugin Tutorial
Elementor Angie Ai Plugin Tutorial
Quick Tips - Web Desiign & Ai Tools
How to Speed Up Your WordPress Website with WP Rocket ⚡Tutorial 2026
How to Speed Up Your WordPress Website with WP Rocket ⚡Tutorial 2026
Matt Tutorials
The masks we wear | Zora Krstić | TEDxLuxembourgCity
The masks we wear | Zora Krstić | TEDxLuxembourgCity
TEDx Talks