Why I Dislike Working With Frameworks – Even Though They Make Sense in Some Situations
Frameworks, like jQuery, are some of the most popular, and most widespread assistants used on websites. The framework allows you to access and manipulate HTML elements fast and easily, as well as style them via CSS. Personally, I'm not a fan of these frameworks, and try to avoid them whenever possible. This doesn't always work, but it can be done without any issues quite often.
jQuery and Co. and its Large Footstamp
Especially jQuery has become some all-round tool for JavaScript over the last couple years. The framework provides a vast array of methods, elements, and events, most of which won't be used by the majority of users. Although the current compressed version of jQuery only weighs about 85 kilobytes, a majority of the framework would remain unused in my projects. You might call me picky for worrying this much about 85 kilobyte. But as a web developer, a slim code that only contains what I actually need is important to me. jQuery has become some standard in web development. Thus, a lot of other frameworks were developed as plugins for jQuery. So, if I would want to use them, I'd have to use jQuery as well. Here, the disadvantages of these frameworks become evident. After all, I would only need jQuery to use that plugin. To me, 85 kilobytes are too much to justify that.Redundant: Often, JavaScript Can do Just What jQuery Does
With the introduction of HTML5, JavaScript took a huge leap ahead as well. Many functions that were previously exclusive to jQuery are available as native JavaScript methods as well. For example, this applies to adding and removing JavaScript classes. The "classList"-API enables you to realize this in a way that's very similar to jQuery. One of the most important functions in jQuery is the option to access any desired element via "$()" - following CSS selectors. By now, even this unique feature has been implemented in JavaScript via the method "querySelector()".document.querySelector("ol li").classList.add("new");
In the example, the class "new" is assigned to all "<li>" elements that are children of an "<ol>" element. In jQuery, an according invocation is barely shorter - but not less complicated.
$("ol li").addClass("new");
So, in a lot of cases, I don't even need jQuery, as I can work in a similarly simple way using JavaScript.
“The two methods “getElementsByTagName()” or “getElementsByID()” accomplish the goal significantly faster.”
Will jQuery not fall back onto the JS functions available? For example, if you search for an element using $(‘#myelem’), then jQuery should it theory fall back to using the JS function getElementsByID(‘#myelem’).
We all have that pragmatic approach, “I can see where it may be useful”. Think different: The idea of common libraries like that, even larger than needed is mitigated by using a common CDN like Cloudflare (www.cdnjs.com). Think about that, a user can visit a site, probably cache the library in question so when they visit your site, they already have it. CDNs have caching, gzip, fewer hops…
You can make custom jQuery builds online (an some other libraries), trim what you don’t want yourself, but for the most part it is intended to be the kitchen sink.