Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
Reading offsetHeight triggers layout and takes a long time

I'm trying to improve my code performance. There's a line of code that takes more time than all of the other code combined. Take a look at the highlighted function below

screenshot of performance tab

It takes 125ms to read the offsetHeight. Here's the code that the performance tab highlights

const navBar = document.querySelector('.navigation.fixed');
if(navBar){
    const navBarHeight = navBar.offsetHeight,
        isRetracting = navBar.classList.contains('retracting');
    let scrollPos = window.scrollY;
...

I don't see what's so difficult about this that the browser is spending such a long time to read this height. Can someone explain to me what could be the reason for it?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!