Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda