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

93
Visualizações
Load script tag before page load

I have a project and I should load JS right after open tag of body and before any objects load.

I use this way, but I wanna know if there is a better way possible for clean code or anything else

<html>
<head>
.......
</head>
<body>
  <script src="./js/checkRtl.js"></script>

  <h1>Hello World</h1>
  // OTHER COMPONENTS
</body>
</html>

checkRtl.js contains

const lang = localStorage.getItem('userLanguage') || "en";

if (lang !== 'en')
    document.body.classList.add("rtl");

here I use body tag in checkRtl file to check if its RTL or not, but I want just check body then load objects just to don't make the page change direction of objects after they loaded.

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

0

The way you're doing it currently just great. If I were you, I'd store it in the header to be a bit cleaner, as thats where you import things, but otherwise it's perfectly fine here.

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