简体   繁体   中英

Insert Jquery after another script

i want to insert Jquery library in my HTML, but i can't place it on the header of file. I need to include it after some scripts im running. Do you know any way to do this without getting an error?

您可能正在尝试在加载jQuery库文件之前在脚本中调用jQuery。

You only have to load jQuery before your scripts that use it. Other scripts that don't use jQuery can go before it if you want.

For example, if you want to include jQuery in a script tag at the end of the body and then include some scripts that use jQuery after that, you can do it that way.

If you are constructing your own site/page then you may be able to control this enough by making sure jQuery is included before the other files. However, if you are using something like WordPress or other dynamic CMS platforms you may not be able to stop something from referencing jQuery before it exists.

Check out this github project for jqShim that might help. You can include the very basic dom ready functionality in the head while moving the bigger/larger/slower/complete jQuery download to the bottom of the BODY (but before any plugins). As long as the code that calls jQuery is doing something like:

jQuery(function($) { ... doing something when ready ... });

Those calls can still be made in the body, after using the jqShim, and will behave as expected. Let me know if it proves to be helpful!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM