Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

94
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda