[英]What is the best/fastest way to include my external javascripts? I use jQuery
I am nearly done with my site and am optimising it at the moment; 我差不多完成了我的网站,目前正在优化它; I would like to know the best and fastest way to include all my external javascript files. 我想知道包含所有外部JavaScript文件的最佳和最快的方法。 I want the site to download as quick as possible, but it has quite a few (10 or so) external javascript files that need to be loaded; 我希望网站尽快下载,但它有很多(10个左右)需要加载的外部JavaScript文件; some are jQuery library files from Google's AJAX API and some are mine. 一些是来自谷歌AJAX API的jQuery库文件,有些是我的。
I'm sure I read a while ago that I could call all external scripts using a bit of javascript code, in effect, only calling one external file from the browsers point of view. 我确定我刚才读过,我可以使用一些javascript代码调用所有外部脚本,实际上,只从浏览器的角度调用一个外部文件。
Do you see what I mean? 你明白我的意思吗?
Many thanks 非常感谢
What you're referring to (using Google's AJAX Libraries service) is another way to handle this that falls under the heading of a CDN (Content Delivery Network). 您所指的是(使用Google的AJAX Libraries服务)是处理此问题的另一种方式,属于CDN(内容交付网络)的标题。 The idea being that the file is stored in multiple plallllces and the client will download the closest (and that result will be saved). 这个想法是文件存储在多个plallllces中,客户端将下载最接近的文件(并且将保存该结果)。
That's hard or just awkward to combine with other techniques and I've found that doing multiple external loads this way completely erodes any perceived benefit (unless that's your only external load) so I use the method listed above instead. 与其他技术结合起来很困难或者很尴尬,我发现以这种方式进行多次外部加载会完全侵蚀任何感知的好处(除非那是你唯一的外部负载),所以我使用上面列出的方法。
My guess is to combine the library files to just one file (except the ones hosted at Google). 我的猜测是将库文件合并到一个文件(谷歌托管的文件除外)。 Each call to your server takes quite some resources, so you're better off with just one call. 每次拨打您的服务器都需要相当多的资源,所以只需拨打一个电话就可以获得更好的服务。 You can even combine the files online: 您甚至可以在线组合文件:
我建议将所有脚本合并到一个JS文件中,然后使用YUI Compressor将它们打包成一个较小的文件。
要使用脚本浏览器必须下载它们,所以我认为没有任何区别你如何称呼它们...除非你在服务器上使用压缩并在客户端解压缩。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.