开发者

Will including javascript files from googles site slow my load time?

开发者 https://www.devze.com 2023-01-20 02:17 出处:网络
so i开发者_StackOverflow中文版m trying to include this file for an application http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js

so i开发者_StackOverflow中文版m trying to include this file for an application

http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js

would including it as this url slow the load time of my site when using an application that requires it?

as opposed to downloading this file and including it locally


Quite the opposite, Google's global network of CDN edge servers is almost certain to give you faster average response times even on the first request.

However, you should never use the "latest" URL like that. In order to reliably start serving newer versions when the time comes, the "latest" URL must respond with a very short expires header, which makes return visits even slower than hosting it on your own server.

The full version URL (e.g. http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js) is served with a +1 year expires header. Always use a fully specified version. Make sure to also do that for initial major version revs, like 1.5.0 instead of 1.5.


I would think about positive points which over-weigh the negative ones when using google CDN. You might want to read:

  • 3 reasons why you should let Google host jQuery for you
  • 6,953 reasons why I still let Google host jQuery for me


For the first time, yes. After that, as long as the file has not changed, the browser should cache it, so the load time would not be very high.

Anyway your site (with all its images and javascript files) should load, and this will also take some time the first time. The overhead (on top of this) caused by an external hosted script should not be very high.

Whether you want to use a local version depends on your requirement as well as the purpose of the js file.

jquery.js can be downloaded and used from your server, but, for instance, it does not make much sense to have google analytics scrips locally.

Note: You might see the delay during development because all other files load from the same (local) network, and google hosted scripts load from the internet. (I mention this because someone in my previous project panicked that "google is slow" during a similar scenario. We were using google anayltics scripts)

0

精彩评论

暂无评论...
验证码 换一张
取 消