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

92
Views
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 answers
Answer question

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 Report
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!