Home > Article > Web Front-end > Writing high-performance JavaScript script loading and execution_javascript skills
The script can be placed in the head of the HTML page or in the body.
Put the script in the body. When the browser encounters the <script> tag, the browser does not know whether the script will insert text or html tags, so the browser will stop analyzing the html page and execute the script. When adding scripts using src, the browser will do the same thing. Page rendering and user interaction will be completely blocked while the script is processing. Script downloading and execution blocks the downloading of other resources, such as images used to render the page. (Although many browsers have implemented the technology of parallel downloading of scripts, this problem is still not solved) <br>Location of the script<br>In view of the above reasons, the script should always be placed at the bottom of the page, that is, in front of </body> . <br><strong>A simple example:</strong> <br></p>
<div class="codetitle">
<span><a style="CURSOR: pointer" data="780" class="copybut" id="copybut780" onclick="doCopy('code780')"><u>Copy the code</u></a></span> The code is as follows:</div>
<div class="codebody" id="code780"> <br><html> <br><head> <br><title>Script Example</title> <br><link rel="stylesheet" type="text/css" href="styles.css "> <br></head> <br><body> <br><p>Hello world!</p> <br><script type="text/javascript" src="file1 .js"></script>