Closing an external jQuery file in $ (document) .ready ()

I have external javascript files containing jQuery only. Should I enclose all the code in each of these external files in $ (document).ready() ? What is the best practice here?

Thanks!

+2
source share
2 answers

Include the jquery script above them on your page and include each of the other scripts included after it in the usual way. But inside each of these scenarios, put all the necessary code in the $ (document) .ready () structure. You can use it several times; you are not limited only once.

+2
source

Should I enclose all the code in each of these external files in $ (document) .ready ()?

Only if they need to wait for the DOM to complete before they start.

What is the best practice here?

By combining them into a single file, minimizing it and serving it with the corresponding HTTP compression and cache, it controls it.

+4
source

Source: https://habr.com/ru/post/1381068/


All Articles