javascript - understanding of asynchronous modules
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-07-05 10:49:39
0
2
918

For synchronization modules, the module must be loaded into memory in advance.
For asynchronous modules, for example, its implementation of requirejs relies on front-end and is executed in advance. Isn't this also loaded into memory in advance? Then why is it said to be asynchronous? After reading a lot about AMD and CMD, I just don’t quite understand the difference between synchronous module loading and asynchronous module loading.

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
淡淡烟草味

This mechanism has little to do with [memory], and can be understood more as [script download timing].

The particularity of the front-end is that the size and download time of the script file will directly affect the page performance. In the specification of synchronous loading, all dependencies must be downloaded before the script can be executed.

In the specification of asynchronous loading, the required script will be loaded only when the code runs to the required location. For example, in a huge single-page application, the script on the home page can be very light, and when entering a certain function page, the required modules can be loaded asynchronously, which will greatly help the performance.

我想大声告诉你

The asynchronous loading of requirejs essentially appends the <script> that needs to be loaded asynchronously in the <head>. These <script> elements have the async attribute to achieve non-blocking asynchronous loading. Then monitor the loading completion status of each script through onload to realize the sequential loading order of multiple scripts with dependencies. You can use async and onload to implement simple asynchronous loading functions, but it still takes a lot of effort to implement functions like requirejs.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!