Where do you include the jQuery library from? Google JSAPI? CDN?

后端 未结 16 1613
攒了一身酷
攒了一身酷 2020-11-22 09:21

There are a few ways to include jQuery and jQuery UI and I\'m wondering what people are using?

  • Google JSAPI
  • jQuery\'s site
  • your own site/serv
相关标签:
16条回答
  • 2020-11-22 10:09

    I might be old-school about this, but I still frown on hotlinking. Maybe Google is the exception, but in general, it's really just good manners to host the files on your own server.

    0 讨论(0)
  • 2020-11-22 10:10

    I host it with my other js files on my own server, and, that's that point, combine and minify them (with django-compresser, here, but that's not the point) to be served as just one js file, with everything the site needs put into it. You'll need to serve your own js files anyway, so I see no reason to not add the extra jquery bytes there too - some more kbs are much more cheaper to transfer, than more requests to be made. You are not dependent to anyone, and as soon as your minified js is cached, you're super fast as well.

    On first load, a CDN based solution might win, because you must load the additional jquery kilobytes from your own server (but, without an additional request). I doubt the difference is noticable, though. And then, on a first load with cleared cache, your own hosted solution will probably always be much faster, because of more requests (and DNS lookups) needed, to fetch the CDN jquery.

    I wonder how this point is almost never mentioned, and how CDNs seem to take over the world :)

    0 讨论(0)
  • 2020-11-22 10:11

    I have to vote -1 for the libraries hosted on Google. They are collecting data, google analytics style, with their wrappers around these libraries. At a minimum, I don't want a client browser doing more than I'm asking it to do, much less anything else on the page. At worse, this is Google's "new version" of not being evil -- using unobtrusive javascript to gather more usage data.

    Note: if they've changed this practice, super. But the last time I considered using their hosted libraries, I monitored the outbound http traffic on my site, and the periodic calls out to google servers were not something I expected to see.

    0 讨论(0)
  • 2020-11-22 10:17

    jQuery 1.3.1 min is only 18k in size. I don't think that's too much of a hit to ask on the initial page load. It'll be cached after that. As a result, I host it myself.

    0 讨论(0)
  • 2020-11-22 10:18

    One reason you might want to host on an external server is to work around the browser limitations of concurent connections to particular server.

    However, given that the jQuery file you are using will likely not change very often, the browser cache will kick in and make that point moot for the most part.

    Second reason to host it on external server is to lower the traffic to your own server.

    However, given the size of jQuery, chances are it will be a small part of your traffic. You should probably try to optimize your actual content.

    0 讨论(0)
  • 2020-11-22 10:20

    I wouldn't want any public site that I developed to depend on any external site, and thus, I'd host jQuery myself.

    Are you willing to have an outage on your site when the other (Google, jquery.com, etc.) goes down? Less dependencies is the key.

    0 讨论(0)
提交回复
热议问题