I just started creating a html file and wanted to use jquery. When I use the jquery from my local machine like this, it works fine.
<script src="jquery.min.js"></script>
But when I try to use this, it does not work
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
I am not able to use any jquery functions when I load the script like this.
What am I doing wrong here?
EDIT: Btw, my html file is on the local machine in drive C:/
Note: Use the full path to your downloaded jQuery file. In my case, both HTML and jQuery file is in the same folder. Now, we will see how to load local jQuery in case our CDN fails. Write the following lines of code, and it will add jQuery from the machine when CDN fails.
Projects In JavaScript & JQueryGoogle provides CDN support for jQuery via the googleapis.com domain. The latest version of Google CDN provides four different types of jQuery versions- normal (uncompressed), minified, slim, and slim & minified. Google CDN provides the jQuery via ajax.googleapis.com domain.
There are a lot of people that say you should always use a CDN for libraries like jQuery (and other popular projects, as well). They say this for good reason. Using a CDN, as noted already, can reduce latency and allow browsers to cache a common file so it doesn't even have to load it from a server.
If you don't need HTTPS support, the fastest CDN is actually the official jQuery CDN, provided by Media Temple. Google's Libraries API CDN is a good second choice after that. If you need support for HTTPS, your best option is Google's Libraries API CDN.
Your url is incomplete. I believe they leave off the http to show that you can use either http or https, because if you're on a server you don't need it. You only need to add it in if you're running off your file system.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With