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
Action Steps
- Avoid using getBoundingClientRect() in loops to prevent layout thrashing
- Use caching or memoization to store the results of getBoundingClientRect()
- Consider using alternative methods such as getClientRects() or DOMRect
- Optimize your code by reducing the number of DOM reads and writes
- 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------------------)

# 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
[](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

_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
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------------------)

# 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
[](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

_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
DeepCamp AI