Scoring Your JavaScript Library

Choosing a library for your Web application can be difficult. Both HTML5 Programming with JavaScript for Dummies and CSS3 for Dummies emphasize the need to choose libraries with care. There are all sorts of considerations, such as whether the library enjoys popular support and has a good upgrade policy. You also need to know whether the library is secure and performs all the tasks you require of it in the manner you want them performed. These books do a great job of helping you understand the requirements for choosing a library.

At the time I wrote these books, jQuery was the most popular library available. In fact, both books emphasize use of jQuery for programming needs. It turns out that jQuery is still the most popular library around and for good reason, the producers of jQuery have done just about everything right, so developers continue to support them. If you need general interface and low level programming support, jQuery and jQuery UI are good places to start. What it really comes down to is reducing costs and getting work done faster. Money drives everything on the Internet, including your next project.

Two libraries simply can’t meet every need. Developers often use a wide variety of libraries to get the job done. Choosing the right library can be difficult. There are literally hundreds of them, all purporting to do the job faster, better, and for less money (when money is directly involved in the equation). Choosing the wrong library can incur huge penalties. That’s why a site such as Libscore is so important. You can use Libscore to find the top:

  • JavaScript Library
  • Script
  • Site Using JavaScript

The last option is the most important because it tells you what the top sites are and which libraries they use to achieve their goals. By viewing the site and seeing how it uses a library, you can make intelligent decisions for your own site. Exploring Libscore doesn’t take long, but can net you huge gains in productivity that translate into reduced costs and fewer errors.

I receive more than a few e-mails each week about JavaScript, HTML5, and CSS3. Readers really do want to know my opinion about this library or that. Unfortunately, my ability to test every library out there is limited. In fact, let’s be practical—even if I were to attempt to perform the task full time, I still wouldn’t have time as an individual to test all the options. So, using a site such as Libscore is the best option that I can offer you. I’d love to hear your opinions about Libscore or any other site offering the same functionality at John@JohnMuellerBooks.com. If you send me information about another library scoring site, please make sure it actually works with JavaScript or another viable Web technology.

 

Sometimes Newer Really Isn’t Better

I normally spend a good deal of time telling readers to use the latest versions of libraries because the newer versions will have additional functionality and contain bug fixes for issues that have surfaced since the library was released. There are some situations where this tactic doesn’t work and one of them appears in Chapter 2 of HTML5 Programming with JavaScript For Dummies. The example originally displayed information about the host browser, but the property used to perform that task, browser, has been deprecated in jQuery 1.9.

The easiest way to fix this problem is to use a version of jQuery that does support this property. The change is relatively small. All you need to do is change the line that reads

to read

The change will force the application to use an older version of the jQuery library. As an alternative, you can also add a call to the jQuery migrate library so that the code looks like this:

<head>
   <title>Detect a Browser</title>
   <script
   </script>
   <script
   </script>
</head>

The jQuery site recommends using feature detection instead. Although this feature is directly supported in the latest version of jQuery, there are problems with it as well. The most important issue to consider is that the site tells you outright that the library might have certain features pulled without notice or with a long deprecation cycle, which means that you code could simply stop working at some point. It’s a poor way to detect the kind of browser that you’re using because it’s unreliable. The technique shown in Chapter 2 of the book is far more reliable at the moment.

The point of this post is that there aren’t any absolutes when it comes to coding practice. You need to know when to break the rules. Let me know if you encounter any difficulties with my solution to the problem at John@JohnMuellerBooks.com. If someone has a better jQuery-oriented solution to share, contact me because I’d love to hear about it.

 

jQuery 2.0 and My Books

A number of readers who know that I work extensively with jQuery have written to tell me about changes to the support it provides for older versions of browsers. In fact, you can read about these changes in a recent InfoWorld article, “jQuery 2.0 drops support for old versions of Internet Explorer.” The article title is misleading because there are also apparently changes for other browsers such as Firefox and Chrome as well. My advise is to test your application to ensure it actually works as anticipated with the browsers you want to support before you upgrade to jQuery 2.0 in a production environment.

Of course, the concern from readers is that the code in my books will suddenly stop running in their browsers. There is no need for concern. Even though the examples in my latest book have an URL that points to http://code.jquery.com/jquery-latest.js, if you follow the link you’ll find that it actually uses the 1.9.1 version of the library, not the 2.0 version. If you want to be absolutely certain you won’t encounter any problems, you can always change this URL to http://code.jquery.com/jquery-1.9.1.js, which ensures you’ll continue using the 1.9.1 version no matter how the library changes its site.

As to whether I plan to use the new version of the library in upcoming books, it depends on what I see as trends in the market and requests that I receive from readers. As things are now, I probably won’t visit the 2.0 version in my books unless readers specifically request it. Even then, the majority of examples in my books will continue to use the 1.9.1 version until such time as the older browsers it supports lack sufficient market presence to make it a worthwhile tradeoff to continue using the older library. In other words, I’ll continue to support the version of the library that works for most people.

Your input is important to me. If you have a particular preference that differs from what I have stated in this post, please let me know at John@JohnMuellerBooks.com. My goal is to provide books that meet the needs of as many people as is possible. At some point, if enough readers find that the older examples in my books simply don’t work, I’ll do what I usually do and provide updated examples in my blog. Please be sure to let me know your thoughts about third party JavaScript libraries in general and jQuery in specific.

 

Using jQuery and jQuery UI to Enhance Web Apps

As I work more and more often with Web apps (applications), rather than Windows-specific applications, I have become aware of the tremendous amount of developer support that’s available for anyone on any platform when creating this application type. It’s possible for someone who works predominantly on the Mac to write code that works just fine for someone who works most of the time on a Windows system. In fact, the entire idea of platform becomes meaningless when working with Web apps. jQuery and jQuery UI are a huge part of the third party support available to anyone writing Web apps. In fact, it’s hard to find Web apps of any size that don’t rely on these two libraries (many examples of smaller applications do exist).

Third party libraries are an exciting part of working with Web apps because they make it possible to create apps that look similar (possibly precisely the same) on a number of platforms without the work usually required to pull this feat off. jQuery and jQuery UI are used quite often in this capacity. In fact, they’re used often enough that I wrote an article about them entitled, “Using jQuery UI to Your Advantage.” Instructions and examples on using these libraries also appear in HTML5 Programming with JavaScript For Dummies. I like these libraries so much that customization instructions for them will appear in an upcoming book, CSS3 for Dummies (work on this book will begin in May—be sure to keep your eyes peeled for further details).

Of course, you might wonder why jQuery and jQuery UI are so successful. My experience is that these libraries are incredibly well written, work with a wide variety of browsers, are well supported, and provide great documentation. Most importantly, the two libraries provide developers with needed functionality and flexibility. It’s possible to create a unique application using just these libraries with well-documented tweaks and event handlers. In short, these two libraries have everything needed to create a successful library—one that everyone will enjoy using.

There are many other libraries available to Web developers and I plan to explore many more of them as time permits. I find it interesting that even if I were to devote myself entirely to working through all of the available libraries, there probably wouldn’t be time to explore them all. That’s why I’d like to know about your favorite library and why you find this particular library so useful. I’m not interested in hearing about something mundane—the library needs to do something special, such as providing functionality not found in other libraries currently available. I’m looking for libraries that are well documented and are used by a wide variety of developers to create great looking Web apps. Let me know about the library of your dreams at John@JohnMuellerBooks.com.