I just made loading screen with Javascript and am wondering which part of HTML Document it must be placed. I mean on inside of or before closing tag??? Some documents say it must be placed on because it has to be loaded before any contents, but it seems to work well even though I put it before .
Could you tell me which part of HTML Document I "must" or "had better" put the scripts? Is there difference in case with "defer" or "no defer"??
window.addEventListener('load', function () {
document.querySelector('#js-loading').classList.add('hide');
});
.loading {
opacity: 1;
transition-property: visibility, opacity;
transition-duration: 0.2s;
}
.loading.hide {
visibility: hidden;
opacity: 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="css/style.css">
<script src="js/script.js"></script> //Position A ???
<script src="js/script.js" defer></script> //Position A with defer???
</head>
<body>
<div class="loading" id="js-loading">
<div class="loading-img"><img src="images/loading.svg" alt=""></div>
</div>
<div>content</div>
<script src="js/script.js"></script> //Position B ???
<script src="js/script.js" defer></script> //Position B with defer???
</body>
</html>