What's faster for including scripts, using CDN (Google) or storing them locally in website's root?

前端 未结 7 1344
眼角桃花
眼角桃花 2020-12-02 14:55

What\'s faster for including scripts, using CDN (Google) or storing them locally in website\'s root?

7条回答
  •  执念已碎
    2020-12-02 15:08

    If you mean the core jQuery libraries, use the google CDN for an internet-facing site (as opposed to an internal one).

    The CDN has the following advantages you'll find hard to compete with:

    • More servers
    • The bandwidth (you don't pay for)
    • Geolocation (lower response time)
    • Redundancy
    • The optimized caching settings
    • Chance the user has already cached the file from there
    • Parallelized downloads, user can grab other content from your site at the same time

    Though you can configure the cache headers just like they do, you probably can't serve the file faster. That being said, the library/CDN is only part of the puzzle. Miscellaneous plugins and code you have should also be minified, combined and served via gzip.

提交回复
热议问题