如何在另一个javascript文件中包含jquery
问题描述:
我有一个javascript文件,我想在这个js文件中包含jquery。你有什么建议吗?
I have a javascript file and I want to include jquery in this js file. Do you have a suggestion?
答
在包含你自己的JavaScript之前,只需包含jQuery的JavaScript:
Simply include the JavaScript for jQuery before you include your own JavaScript:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script src="path/to/your/script.js"></script>
虽然其他人建议简单地将jQuery复制并粘贴到您自己的JavaScript文件中,但包含jQuery真的更好与规范源分开,因为这将允许您利用浏览器和中间服务器为该文件完成的缓存。
Though others have suggested simply copying and pasting jQuery into your own JavaScript file, it's really better to include jQuery separately from a canonical source as that will allow you to take advantage of the caching that your browser and intermediate servers have done for that file.