dongping6974 2010-07-22 19:52
浏览 93
已采纳

包含最新版jQuery的最佳方法是什么?

I'm developing sites using Wordpress and I want to use the lates version of jQuery.

To make sure I use the lates version, I have found this piece of code from Binary Bonsai's example.

What I see, is that he actually links to jQuery at Google API.

So my question is, what is better.

To link to jQuery on an external page?
http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js

or to have the jquery file locally?
wp_enqueue_script('jquery', '/js/jquery-1.4.2.min.js');

UPDATE

Thanks to Colin, the answer is actually here:
Why should I use Google's CDN for jQuery?

But tjust in case you don't have Google in your search term, like me, I'll copy the answer from John Gietzen

  1. It increases the parallelism available.
    (Most browsers will only download 3 or 4 files at a time from any given site)

  2. It increases the chance that there will be a cache-hit.
    (As more sites follow this practice, more users have the file already ready.)

  3. It ensures that the payload will be as small as possible.
    (Google can pre-gzip-compress the file, making the time-to-download very small.)

  4. It reduces the amount of bandwidth used by the server.
    (Google is basically offering free bandwidth.)

  5. It ensures that the user will get a geographically close response.
    (Google has servers all over the world, further decreasing the latency.)

  • 写回答

6条回答 默认 最新

  • douzhi7661 2010-07-22 19:56
    关注

    You can leave out the minor or dot versions when linking to the google CDN copies, like this:

    Given this flexibility, I much prefer the remote version, it's quick to get bug fixes by just changing the URL and the file's loaded faster (in most cases) because it's pulled from another domain (and not in the count of parallel requests to your domain). There are other related questions on this, here and here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题