Usage: <SCRIPT src = "../cgi-bin/delscript. js" Defer> </SCRIPT>
Defer is used to execute the script after the file is loaded, so that the object cannot be found.
In addition, defer is equivalent to executing after the page is completely in, which is equivalent to window. onload, but the application is more flexible than window. onload!
Defer is an "unsung hero" among the powerful functions of the script program ". It tells the browser that the script segment contains code that does not need to be executed immediately and is used together with the src attribute. It can also
These scripts are downloaded in the background, and the foreground content is displayed to the user normally.
-- The script is executed after the file is loaded.
Note the following two points:
1. Do not call the document. Write command in the defer script section, because document. Write will generate a direct
Output result.
2. do not include any global variables or functions to be used to execute the script immediately in the defer script section.
A common method to optimize performance is to set the "Defer" attribute in the <SCRIPT> label when the script does not need to run immediately.
(The script is not included in a function block, so it will be executed during the loading process .)
After setting the "Defer" attribute, ie does not have to wait until the script is loaded and executed. In this way, page loading will be faster. In general, this also indicates that it is best to place the script immediately in the function block and
Onload of the document or body object
Handle. This attribute is useful when some scripts are executed depending on user operations, such as clicking a button or moving the mouse to a certain area. But when some scripts need
The benefits of using the defer attribute are not great during or after page loading.