jquery loaded async and ready function not working

后端 未结 6 1242
说谎
说谎 2021-01-14 02:40

In order to optimize the load of my document, I use to load jquery async like that



        
6条回答
  •  轮回少年
    2021-01-14 03:23

    Since jquery script is loaded asynchronously, jquery is not loaded on the moment your script is executing. So you need to wait for it to load by subscribing on load event like this:

    
    

    Then listen for a load event on this element

    
    

    But I don't know why someone wants to do things like this.

    To optimize page loading speed it is better to put all you javascript at the end of the body, so content will be loaded first, and scripts won't delay page rendering event if it's synchronously loaded.

    Edit: I agree with comment and consider previous paragraph not the best way of loading jQuery to the page

提交回复
热议问题