How to load local jQuery file in case CDN is not available ?
The jQuery library contains the following features:
- HTML/DOM manipulation
- CSS manipulation
- HTML event methods
- Effects and animations
There are a number of ways you can use jQuery in your application, one being easier than the others. Below are some of the methods that you can use to load local jquery file.
Method 1: Using jQuery CDN (Content Delivery Network)
Example: In this example, we will simply include the CDN line in the script tag and If you click the submit button you will see your name coming up as alert in the browser.
Now we will see how to load the local jquery file in case if above CDN is not available.
Method 2: Download jQuery to use it locally.
Downloading the jQuery library from here. There are two versions of jQuery you can download.
- Production version: This is for your live website because it has been minified and compressed
- Development version: This is for testing and development (uncompressed and readable code)
Example: In this example, instead of using CDN we will download library file “jquery.min.js” and If you click the submit button you will see your name coming up as alert in the browser.
Note: The path in the source (src) of the script tag needs to be configured properly. It should be set to the right path for jQuery to work perfectly.
You can also install jQuery as a node package using npm (node package installer).
npm install jquery
You can also install it using the yarn CLI, the command being as follows.
yarn add jquery