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.
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.