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

254
Visualizações
Why does a script at the end of the body block the page from loading?

If I add an alert in the page head the alert shows up normally and after clicking on OK the website loads, but when I move the alert into the end of the body element the webpage (according to YT videos) should load immediately but it doesn't. It still waiting on me on clicking "OK".

So where I did mistake?

<body>
  <div id="contact-us">
    <h2>Contact Us</h2>
    <p>You can contact Mr Green in various ways ...</p>
    <div class="contact-method">
      <h3>By Phone</h3>
      <p>222-222-FISH</p>
    </div>
    <div class="contact-method">
      <h3>By Email</h3>
      <p>iammrgreen@green.com</p>
    </div>
    <div class="contact-method">
      <h3>By carrier pidgeon</h3>
      <p>To do this, order your podgeon at www.mrgreenspidgeonemporium.com</p>
    </div>
  </div>

  <a href="#top">Go to top</a>

  <script>
    alert("Yo Ninja, welcome to my website!");
  </script>
</body>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can do an experiment for example with setTimeout.

In this snippet if the timeout is too small the alert will appear before anything is painted on the screen, slightly bigger and the whole screen gets painted before the alert appears. It doesn't happen in bits.

<body>
  <div id="contact-us">
    <h2>Contact Us</h2>
    <p>You can contact Mr Green in various ways ...</p>
    <div class="contact-method">
      <h3>By Phone</h3>
      <p>222-222-FISH</p>
    </div>
    <div class="contact-method">
      <h3>By Email</h3>
      <p>iammrgreen@green.com</p>
    </div>
    <div class="contact-method">
      <h3>By carrier pidgeon</h3>
      <p>To do this, order your podgeon at www.mrgreenspidgeonemporium.com</p>
    </div>
  </div>

  <a href="#top">Go to top</a>
  <script>


function afterwait() {
  alert("Yo Ninja, welcome to my website!");
}
setTimeout(afterwait, 10);
</script>
</body>
about 4 years ago · Juan Pablo Isaza Relatório
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