For a complex system, the client's JS may have hundreds, if all loaded into the user's browser, on the one hand will lead to redundant network transmission, on the other hand, the browser resolution of a large number of JS will lead to performance degradation, these two points will significantly affect the user can detect performance. So for JS loading, is dynamic, this dynamic performance in two ways:
Can not load the JS will never load.
The JS that needs to be loaded is not loaded until it is actually used.
1, can not load the JS will never load
Take the process of landing as an example:
An attempt to log in involves two scenarios, one when the user refreshes the page try to automatically log on according to the current token, the other is the user in the last login to save the user name and password, both of which are successful landing, do not need users to land again, and thus do not need to load formlogin this JS.
2, need to load the JS in until it is actually used to load
For a functional module, a display-related menu item is generated only if the current user has permissions for the module. Now when a menu item for the module is clicked for the first time, the associated JS of the module is loaded: