Blog

7 Benefits of jQuery

By Martin Schaeferle

  

jquery1

jQuery makes using a Web page's DOM (document object model), adding effects to the page, animating elements, and executing Ajax calls to the server extremely simple, hiding the complexity of the underlying JavaScript. There are a number of benefits to using jQuery instead of writing your own raw JavaScript or building your own library.

jQuery is lean and mean. Please forgive the cliché, but it is an apt way to describe the library. The minimized size of version 1.5 of the library is a mere 83KB, only 29KB when gzip'd. That is probably smaller than a single photo on many Web sites, and the browser only has to download and cache it once for use across all your pages. If you use a content delivery network (CDN), the user's browser can cache it across many Web sites rather than download it for each. jQuery packs a lot into a very small size.

One of the primary benefits of jQuery-a benefit shared with some other JavaScript libraries-is that it seamlessly handles crossbrowser issues.

JavaScript implementations differ among browsers to varying degrees, and it can cause a developer to prematurely and severely age to get everything working across browsers with JavaScript. Relax: the authors of jQuery have done most of the work for you.

jQuery uses a simple, clean, powerful syntax that makes it easy to select the DOM elements on the page you want to change with JavaScript and allow you to chain actions and effects together for efficient code. It is quite common to replace a dozen or more lines of JavaScript with a single line of jQuery code. jQuery uses the CSS (Cascading Style Sheets) version 3 selector specification for selecting elements, so you don't have to learn a different syntax to use jQuery. This assumes, of course, that you're familiar with the CSS3 syntax.

jQuery is highly extensible. As mentioned earlier, the core jQuery library is kept tight and focused, keeping out non-essential features. It also provides a plugin framework that makes it easy to extend jQuery, and there are both official jQuery plugins as well as thousands from third parties. This way your page has to download only the specific set of features it needs. Any time you need a feature not included in the core jQuery library, there is a good chance that someone has already written a plugin that does what you need.

TIP: You can find a list of available plugins at jquery.com, the home of jQuery, with user ratings to help you find the best ones.

  • jQuery supports building pages using unobtrusive JavaScript, an approach to using JavaScript in Web pages. Among other things, unobtrusive JavaScript is concerned with the separation of functionality between a Web page's structure/content and presentation. This keeps nuggets of code out of HTML elements on the page, such as with event attributes such as onclick. Instead, you wire up event code in a script block, keeping the behavior implemented in code separate from the structure of the page.
  • One of the goals of jQuery is to make things that are hard in JavaScript easy when using jQuery. So jQuery includes many utility functions to do things like trim strings, parse JSON data, check whether one DOM element is within another, and search array elements using a filter.
  • jQuery is one of the most widely used JavaScript libraries available, with support from some of the most heavily trafficked Web sites in the world. According to the jquery.com Web site, Google, Amazon, IBM, Microsoft, Twitter, Dell, CBS News, Bank of America, and many others use it on their Web sites, and it is in use in many open source projects including Mozilla, DotNetNuke, and WordPress. Such widespread use ensures that jQuery will receive active development support for years to come, and a vibrant user community has formed around the library.

If you want to add rich user interactivity or Ajax features to your Web site, there really is no reason not to consider jQuery. Once you learn what jQuery can do and how small and efficient it is, it's easy to understand why Microsoft abandoned its own Ajax Library in favor of jQuery! Even if you begin using jQuery and find some highly specialized situation that the library doesn't support, you can always fall back to writing your own custom JavaScript for that one situation.



Martin Schaeferle

Martin Schaeferle has taught IT professionals nationwide to develop applications using Visual Basic, Microsoft SQL Server, ASP, and XML. He has been a featured speaker at Microsoft Tech-Ed and the Microsoft NCD Channel Summit, and he specializes in developing Visual Basic database applications, COM-based components, and ASP-based Web sites. In addition to writing and presenting technical training content, Martin is also LearnNowOnline's vice president of technology.


This blog entry was originally posted October 03, 2012 by Martin Schaeferle

jQueryVideo