I used JavaScript in script tag in html like this:
<script src="file.js" type="text/javascript"></script>
With use of above code, file.js is linked to our html page. But when we add async or defer to the script tag, file.js cannot be executed in these codes:
<script src="file.js" type="text/javascript" async="async"></script>
<script src="file.js" type="text/javascript" defer="defer"></script>
Could you help me, please? Why such problem I faced with it?
In addition, for more clarifying I add a section of html comprised of file.js loading as follow:
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Dr.Kayvanfar</title>
<meta charset = "UTF-8" />
<link type="text/css" rel="stylesheet" href="Main_CSS.css" />
<noscript> Your browswer don't support JS</noscript>
</head>
<body>
<div id="container" style="width:1500px;margin-left:auto;margin-right:auto;color:blue;">
<div id="header" style="height:100px;background-color:rgb(0,0,0); margin-bottom:20px;margin-top:20px; color:rgb(255,255,255);padding-top:5%">
<span class="topheader">Future Students</span>
<span class="topheader">Current Students</span>
<span class="topheader">Research & Teaching</span>
<span class="topheader">Communities</span>
**<script src="file.js" type="text/javascript" async ></script>**
</div>
</body>
</html>