This article mainly introduces the optimization solution for non-blocking loading performance in JavaScript. This article describes the DeferredScripts extension script, DynamicScriptElements dynamic script elements, XMLHttpRequestScriptInjectionXHR script injection, and other content, if you need it, you can refer to the performance of Javascript in the browser. It can be said that it is the most important availability issue for front-end developers.
Among Yahoo's Yslow23 rules, one of them is to put JS at the bottom. The reason is that, in fact, most browsers use a single process to process the UI and update Javascript to run multiple tasks, and only one task can be executed at a time. How long does Javascript run? How long does the browser wait before it is idle to respond to user interaction.
Basically speaking, this means that the appearance of the script tag makes the entire page wait for parsing and running the script. No matter whether the actual JavaScript code is inline or contained in an unrelated external file, the page download and parsing process must be stopped and wait until the script completes the processing before it can continue. This is an essential part of the page lifecycle, because the script may modify the page content during running. A typical example is the document. write () function, for example:
The Code is as follows:
Script Example