- jQuery for Designers Beginner's Guide Second Edition
- Natalie MacLees
- 422字
- 2021-09-03 10:08:32
Another option for using jQuery
There is nothing wrong with downloading and using your own copy of jQuery, but you do have another option available that can help to improve the performance of your websites. That's to use a CDN-hosted copy of jQuery.
In case you don't know, a CDN is a Content Delivery Network. The premise behind a CDN is that files download faster from servers that are physically closer to a site visitor's location. So, for example, if you're in Los Angeles, California, a copy of jQuery that's on a server in Phoenix, Arizona will download faster than a copy that's on a server in New York City. To help this along, a CDN has a copy of the same file on lots of different servers all around the world. Each time a site visitor requests a file, the CDN smartly routes their request to the closest available server, helping to improve response times and overall site performance.
It won't make much of a difference for the relatively simple examples and pages that we'll build in this book, but for a public-facing website, using a CDN-hosted copy of jQuery can make a noticeable difference. There are a few options out there, but the most popular by far is Google's Ajax API CDN. You can get the information on the latest version available and the correct URL at http://code.google.com/apis/libraries/devguide.html#jquery.
Note
There are several CDN-hosted copies of jQuery available. You can find out about these on jQuery's Download page (http://jquery.com/download/). Just scroll down to the section titled Using jQuery with a CDN to find all your current options.
If you'd like to use the Google CDN-hosted version of jQuery in your files, it's as simple as adding the following line of code to your HTML file, instead of the line we used in the previous section to include jQuery:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
No downloading the file, no saving your own copy; you can just point your <script>
tag directly at the copy of jQuery stored on Google's servers. Google will then take care of sending jQuery to your site visitors from the closest available server. Not only that, but as Google's CDN is so popular, there's a good chance that your site visitor has already visited another site that's also using a Google CDN-hosted copy of jQuery and that they'll have jQuery cached in their browser. This means that your site visitor won't have to download jQuery at all—it's already saved in their browser and available to be used. How's that for improving performance?
- Mastering JavaScript Functional Programming
- Mastering Objectoriented Python
- Vue.js入門與商城開發實戰
- Django:Web Development with Python
- Learning Python Design Patterns(Second Edition)
- Apex Design Patterns
- OpenStack Orchestration
- Linux C編程:一站式學習
- 編程可以很簡單
- 零代碼實戰:企業級應用搭建與案例詳解
- IoT Projects with Bluetooth Low Energy
- Android應用開發實戰(第2版)
- 嵌入式C編程實戰
- TypeScript全棧開發
- Spring Boot學習指南:構建云原生Java和Kotlin應用程序