hide - Understanding jQuery
hide - Understanding jQuery
hide - Understanding jQuery
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Including <strong>jQuery</strong> as an External CDN-based Files<br />
Let’s take a brief look at the basic properties of an externally included file:<br />
1. An external file is a file that is separate from your main HTML file.<br />
2. An external file can be hosted on the same host. In most cases, it is.<br />
It is not necessary, however, for an external file to be located on the same host as your web<br />
page. You can add an external JavaScript file from a separate website and it will still be included<br />
as part of your HTML page. The code will execute.<br />
The <strong>jQuery</strong> locations discussed on the previous page are hosted by Google, Microsoft and the<br />
<strong>jQuery</strong> project itself. They are offered in two flavors HTTP and HTTPS. The latter stands for a<br />
secure connection with SSL.<br />
The subject of the HTTP protocol and secure connections will not be discussed in this book.<br />
However, you must know about Relative URL References with regard to including <strong>jQuery</strong><br />
from CDN locations using either the HTTP or HTTPS protocols.<br />
For various reasons you may be interested in including either HTTP or HTTPS version of the<br />
hosted file from one of the discussed CDNs.<br />
What is a relative reference? It allows us to include external file without mentioning the absolute<br />
location such as www.mywebsite.com/js/script.js. There are similar rules at work when<br />
choosing either HTTP or HTTPS protocols, too.<br />
Some pages on your website will be using the HTTP protocol. Others, HTTPS. In order for<br />
our page to include the right protocol automatically, and according to the HTML specification,<br />
we can use the double slash // symbol, as in:<br />
<br />
Notice the leading // symbol. It means the correctly matched protocol will be used.<br />
This is useful, because, for example, if you were forcing the fixed HTTPS protocol in an externally<br />
included file, on a web page that was itself using HTTP, you would encounter a “mixed<br />
content” security message. The // also helps us properly cache the file. Note that HTTPS can<br />
never be cached.<br />
The golden rule is whenever an external file is offered in HTTP and HTTPS flavors, use only<br />
the // when including it, instead of http:// or https://<br />
This method can also improve page load speed in some cases.<br />
72