1. The Oppressive Magic of jQuery
For many years, both amateur and professional web developers alike have made use of jQuery to ease the burden of bringing a library or web application to market. In a sense, jQuery has been an integral part of web development . Even at the time of writing, jQuery is referenced in the vast majority of public websites, more so than any other library, by a wide margin.
Many developers seem to consider jQuery to be a default requirement. The common thought is: if you are developing a library or a web application, you must depend on jQuery. jQuery is seen as this magical black box that solves all of the woes of web development. Its a framework that is easy to understand and allows even novices to swiftly codify their ideas.
Professionals tend to be quite invested in jQuery as well. After all, this is what we used back when we were novices. Its comfortable. We understand it. We trust it. It has served us well over the years. You dont have to think (much) about the DOM, or browser bugs, or cross-browser behaviors. jQuery solves all of these problems for us... doesnt it?
There is no denying that jQuery is indeed a bit magical. In fact, it allows developers of almost any skill level to create something useful. But at what cost? Consider only understanding the web through rose-colored jQuery lenses. What if you encounter a low-level behavior that jQuery has not properly abstracted? What if you encounter a bug in jQuery? What if you are simply not able (allowed) to use jQuery? This is akin to a city dweller being dropped into the tundra of Siberia. Under these conditions, you are scared, disoriented, and ill-prepared.
Although the likelihood of being whisked away to a foreign land against your will is small, being without jQuery in the future is a much more realistic possibility. If you dont have a good grasp of the DOM, the web API, and JavaScript, you will eventually feel a bit like a cold and confused urbanite, trying to survive the unfamiliar conditions of the Siberian expanse.
One goal of Beyond jQuery is to demystify this seemingly ubiquitous front-end library. The benefits of shedding any blind dependence on jQuery will become clear. At the end of this book, you will have the power to grow further as a web developer given your newfound understanding of the browsers API and JavaScript.
This chapter explores reasons why developers have depended on jQuery, and why they continue to do so. You will see why relying entirely on one monolithic library creates gaps in your knowledge and prevents you from evolving as a developer. I will discuss why a filtered understanding of the web and JavaScript is a potentially hazardous predicament for developers. Given this knowledge, you will be able to better understand the benefits of depending more on your own solid understanding of the fundamentals.
Why Have We Been Using jQuery?
Before exploring how (and why) we should consider removing jQuery from our toolbox, we should first understand why jQuery even exists. Why have countless web developers over the years depended on this library? Why has it been such a central component of websites and applications? Why does it continue to be so ubiquitous? Why have we been using jQuery? We all have our reasons, and there are many reasons indeed. Above all else, jQuery has proven to offer a low barrier to entry. In other words, even amateur or occasional developers find that it allows them to implement a concept or idea with little resistance.
Simplicity
The assumption is that, if you are reading this book, you are already somewhat familiar with jQuery. You have likely already used it in some project, regardless of the size. So lets explore why this library is so easy for developers of all skills levels to use.
Above all else, jQuerys API is intuitive. Want to add a CSS class to an element? Just use the addClass() method . Need to send a POST request? Just use the post() method. And hiding an element is as simple as passing it as a parameter into jQuerys hide() method.
The magic of jQuery is evident in its dirt-simple API. It allows those who have little prior knowledge of the browser or JavaScript to create something intriguing and useful. This is quite appealing and arguably even most appropriate for those who only dabble in web development. Conversely, the simplicity of jQuery is also a potential hazard for professional web developers. If you do not already believe this to be true, we will explore this theory a bit more later on.
Community
On Stack Overflow (at the writing of this book), 1.2 million questions are tagged as JavaScript questions, and 750,000 are tagged as jQuery questions. jQuery is the 6th-most popular tag on Stack Overflow. The next most popular front end library is AngularJS in a distant 21st place, which only has 200,000 tagged questions. Interestingly, 200,000 questions are tagged as jQuery and not JavaScript. In many cases, jQuery is not seen as a JavaScript library. In fact, it is seen as an alternative to JavaScript. A way to address the browser without having to ever deal with the underlying language or API. While the relation to JavaScript may not be clear to some, jQuery has no shortage of developers willing and ready to offer advice on the library. Of the 750,000 jQuery-tagged questions on Stack Overflow, 550,000 (74%) contained at least one upvoted answer.
As of mid-2016, jQuery is still the most used JavaScript library in public websites. In fact, 70% of all public websites depend on jQuery in some way. The next most popular library is Bootstrap, which is only used in 13% of all public sites. With this impressive market share, there is certainly a fair share of users with some working knowledge of the topic.
In addition to the jQuery tag on Stack Overflow and the wealth of different forums and sites dedicated to advising those invested in the technology, jQuerys site has its own active user forums. Help is easy to find, and any problem you may run into has likely already been solved and discussed at length. The reality of a large and mature community is an appealing reason to depend on any software library.
Habit
The large number of examples, blog posts, and forums aimed at jQuery beginners is one of the reasons why those new to web development choose this library to assist with their project. But what about seasoned developers? Why do they continue to use jQuery in their projects? A polished, experienced developer was once an amateur. As amateurs, they may very well have embraced jQuery. Now, with multiple projects under their belt, jQuery has proven itself. And even if some of the flaws in the library have been noticed, they are well understood.
To a seasoned developer, jQuery is consistent and reliable enough. It has become part of the development process. A strong community is a benefit realized by experienced developers as well, and this is yet another reason to stick with such a trustworthy tool.
jQuery has been a prerequisite for everything we write. We mindlessly import it, partially because we have been trained, out of habit, to do so. We have been trained to think that this is a vital component of every web application. Habits are hard to break, especially those that have produced positive results.
Software development can be stressful and frustrating. A typical developer wrestles with a seemingly infinite number of variables on a daily basis. No problem, it seems, is simple to solve. Consistency and predictability of a tool, process, or outcome is highly desired and rare. Can you blame the web development community for relying on a consistent and reliable tool like jQuery for so long?