Home > Web Front-end > JS Tutorial > Analysis of delayed execution problems of js_javascript skills

Analysis of delayed execution problems of js_javascript skills

WBOY
Release: 2016-05-16 16:43:34
Original
1481 people have browsed it

Look at this code:

<body>
  <script src="deffer.js"></script>
  content
 </body>
Copy after login
The content of

deffer.js is:

alert(1)
Copy after login

In this way, the page will be blank until the alert window is closed. Because the alert window prevents the page from continuing to render.

In order to avoid such problems, the deffer and async attributes are defined in the HTML specification. The specific definitions of these two attributes will not be discussed here. Anyway, they are used to tell the browser that this page must be executed after the page rendering is completed. The content of the script, so that the page has been rendered when the script is executed.

<body>
  <script deffer async src="deffer.js"></script>
  content
 </body>
Copy after login

Note that for multiple scripts with deffer or async added, their execution order has nothing to do with the order in which they appear on the page. Even though the HTML specification defines that deffer scripts should be executed in order, browsers do not actually follow this convention.

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template