With the continuous promotion of web technology, more and more applications are processing javascript on the client, making the performance of JavaScript in the browser the most important availability problem faced by developers. This problem is complicated due to the blocking feature of JavaScript. That is to say, when the Browser executes JavaScript code, it cannot do anything at the same time. With the continuous promotion of web technology, more and more applications are processing javascript on the client, making the performance of JavaScript in the browser the most important availability problem faced by developers. This problem is complicated due to the blocking feature of JavaScript. That is to say, when the Browser executes JavaScript code, it cannot do anything at the same time.
This article details how to correctly load and execute JavaScript code to improve its performance in the browser.
01-
Overview
Whether JavaScript code is embedded or in an external link file, the page download and rendering must be stopped and the script execution is complete. The longer the JavaScript Execution process takes, the longer the browser will wait to respond to user input. The reason for blocking when the browser downloads and executes the script is that the script may change the page or JavaScript namespace, which may affect the content of the subsequent page. A typical example is to use document. write () on a page (). Example: Listing 1
Listing 1 JavaScript code embedding example
Source Example