- Part 1: Adding and Loading the Library
- Part 2: Using Selectors
- Part 3: Reacting to Events
- Part 4: Ajax
Adding and Loading the Library
As an external library, jQuery needs to be added to a project in order to use it. While many tools come with or utilize jQuery in different ways, a fresh project using no other tools or project management software will need to add jQuery to the project using one of two different ways.
As a popular library used on many sites, jQuery can be loaded from an external content delivery network (CDN). Hosting common libraries and other resources, many large companies have their own private and sometimes even public networks for loading libraries they or their customers use the most to help with bandwidth and loading concerns.
jQuery can be loaded from many different CDNs. It can be found on Google’s, Microsoft’s, and on CDNJS. To use any of these, simply copy the link provided for the library or additional functionality wanted into a SCRIPT tag.
jQuery can be downloaded in both compressed and uncompressed versions from its website. Often, it is highly recommended to start with the uncompressed version when developing or testing code to more easily diagnose potential problems. When the code is ready for a more public audience, it can be switched over to the compressed version to save bandwidth and space.
Where do I put the jQuery SCRIPT tag?
The reason for this seemingly unusual placement is because these mobile devices load the content as they receive them. Trying to load a library like jQuery can take time. Showing users some content instead of no content as things are loaded is seen as a safe compromise and is generally the recommended practice for situations like this.
Generally, it is recommended to place jQuery in the HEAD section for most projects. For any code that uses or is based on jQuery, it should be placed either right after or in a place that makes the best sense for the project.