Home > Web Front-end > JS Tutorial > JavaScript simple performance issues and study notes_javascript skills

JavaScript simple performance issues and study notes_javascript skills

WBOY
Release: 2016-05-16 17:01:25
Original
931 people have browsed it

1. There should be as few <script> tags as possible (although having more than one will not cause the program to report an error), because each <script> tag will block page rendering when it is initially downloaded <br>2. < Try not to place the script> tag at the top of the page, but try to place it at the bottom of the <body>, because when each <script> is executed, the corresponding js file will be downloaded, and the browser will wait for all js/css to be downloaded. The page will be displayed only after completion <br> 3. When multiple js files need to be imported, usually we write two <script src="..." />, which actually supports one-time import. Multiple, for example: <script src="file1.js&file2.js" /> <br>4. There is an attribute in the <script> tag: defer, which indicates that the script contained in this element will not be modified. DOM, so the code can safely delay execution, but this attribute is only supported by IE4 and Firefox3.5 browsers. I hope you pay attention when using it. If it is used by other browsers, it will be ignored directly. Usage example: </p> <p><script type="text/javascript" src="file1.js" defer /> </p> <p>, test verification defer attribute example: </p> <p></p> <div class="codetitle"> <span><a style="CURSOR: pointer" data="23130" class="copybut" id="copybut23130" onclick="doCopy('code23130')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code23130"> <br><script defer>alert("defer"); </script>
<script>alert("script");</script>
<script> <br>window.onload = function() { <br>alert("load" ); <br>}; <br></script>

Under our normal understanding, the order of execution of this code should be: defer, script, load, but if the order on a browser that supports defer is: script, defer, load, it should be noted here: defer does not follow Executed after the script, but called before the onload event is handled.

Time is limited, so let’s record so much today

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template