Remove JavaScript that blocks rendering and remove javascript
Welcome to my original address: http://www.phpthinking.com/archives/443
The browser must parse the webpage before presenting it to the user. If the browser encounters an external script that is blocked by the system during parsing, it must stop parsing and download the JavaScript. Each time this happens, the browser adds a network round-trip process, which will lead to a delay in the first time the page is displayed.
Suggestions
We recommend that you use the built-in method to process the JavaScript required for rendering the first screen area, and delay loading of JavaScript required for adding other functions to the webpage until the content of the first screen is sent. Note that you must optimize the CSS sending process to shorten the loading time in this way.
Embedded small JavaScript
If the external scripts are small, you can add them directly to the HTML document. By embedding a small file in this way, the browser can continue to render the webpage. For example, if the HTML document is as follows:
Resourcessmall.js
As follows:
/* contents of a small JavaScript file */
Then, you can embed the script as follows:
In this way, you cansmall.js
Embedded in the HTML document to eliminate external requests to it.
Delayed loading of JavaScript
To prevent JavaScript from blocking webpage loading, we recommend that you use the HTML asynchronous attribute when loading JavaScript. For example:
<script async src="my.js">
If your JavaScript resource uses document. write, It is insecure to use asynchronous loading. We recommend that you rewrite the document. write script to use other technologies.
In addition, when loading JavaScript asynchronously, if your webpage loads scripts that depend on each other, be careful to ensure that your application loads scripts in the appropriate order of dependency.
FAQs
-
What should I do if I use a JavaScript Library (such as jQuery?
-
Many JavaScript libraries (such as jQuery) can be used to enhance web pages to add additional interactions, animations, and other effects to web pages. However, most of these actions can be added after the content on the first screen is displayed. Consider whether it is possible to delay the execution and loading of such JavaScript until the webpage is loaded.
-
What should I do if I use a JavaScript framework to construct a webpage?
-
If the webpage content is constructed by the client JavaScript, you should consider whether the relevant JavaScript module can be embedded to avoid additional network round-trip processes. Similarly, rendering on the server can significantly improve the effect of loading the first web page. The method is as follows: Present the JS template on the server and embed the result into HTML, then use the client template after the application is loaded.
How to delete a disabled value through JavaScript
JavaScript:
<Input type = "text" disabled = "disabled" id = "txt1" value = "11"/> 11
<Script type = "text/javascript" language = "JavaScript">
Document. getElementById ('txt1'). disabled = false;
</Script>
Javascript prevents form from submitting data
<Form name = "form1" action = "myresult. jsp" onsubmit = "return checkNum ();">