{"id":25,"date":"2019-01-07T08:13:09","date_gmt":"2019-01-07T13:13:09","guid":{"rendered":"http:\/\/nicholascbrown.com\/blog\/?p=25"},"modified":"2019-09-15T11:26:42","modified_gmt":"2019-09-15T16:26:42","slug":"jquery-in-2018","status":"publish","type":"post","link":"http:\/\/nicholascbrown.com\/blog\/2019\/01\/07\/jquery-in-2018\/","title":{"rendered":"jQuery&#8230; in 2018?"},"content":{"rendered":"\n<p><em>Note: the published date is January 7th 2019, but I wrote this up late in 2018.<\/em><\/p>\n\n\n\n<p>I\u2019ve been slinging JavaScript for much longer than I\u2019ve been professionally developing with it so the first time I used jQuery for a personal project was likely a decade ago around 2008. The Internet was a much different place then. Mobile web dev was still a new concept. HTML5 was used primarily as a buzzword. If you were hip you had Firefox or Opera as your web browser (Chrome was in its infancy and while I don&#8217;t remember using it at that point Wikipedia tells me it was around), but most people stuck with Internet Explorer simply because they didn\u2019t know any better. Internet Explorer was in version 7 (IE7) at the time and if you were to use it today I imagine it would feel very antiquated. That\u2019s the speed technology, particularly software, moves at. While most people shrugged their shoulders and used IE7 simply because that was what they had available to them, developers were troubled by it. <br><\/p>\n\n\n\n<p>I\u2019m not familiar with where the JavaScript spec was in 2008 (at the time I wasn\u2019t interested in the why of JavaScript so much as the how) but I know it wasn\u2019t widely adhered to, and particularly not by Internet Explorer. Microsoft was incredibly cavalier with their browser at the time and are still facing the repercussions of their choices to this day. Thus, due to differences among the browsers, came the need for a library like jQuery. If it had not been jQuery, it would have been some other library. Anything to make development faster: to write code compatible across all of the major browsers and IE versions and to accomplish tasks in less lines. That\u2019s bold stuff and a concept that\u2019s not exclusive to JavaScript as a language. In lieu of a standard template library for JavaScript, you might say jQuery fulfilled that niche. If you\u2019re writing C++ there\u2019s no good reason to write your own linked list implementation or sort methods &#8211; the standard library or even a library like Boostr have sorted that out for you and there\u2019s <em>no <\/em>reason to reinvent the wheel. So I\u2019m not about to say jQuery was a mistake, but I do think using it on a new project in 2018 (or 2019, 2020, <em>current year<\/em>) likely is.<br><\/p>\n\n\n\n<p>If you\u2019re doing any sort of large scale development with JavaScript now you\u2019re likely using one of the big frameworks like Angular, React, or Vue. All of these frameworks offer different ways to think about project structure and DOM management, but the important thing is that they all offer their own mechanisms and methodologies for setting up an interactive web page. Interactivity is the meat and potatoes of why jQuery (and it\u2019s child libraries like jQuery Mobile and jQuery UI) became so popular to begin with. Well, that and simplified AJAX requests, but we\u2019ll come back to that. The point is, if you\u2019re using a development stack that includes React and company, there\u2019s not really a place for jQuery in the mix. There are much better ways to do the kind of things you would do in jQuery built into these frameworks. <br><\/p>\n\n\n\n<p>If you\u2019re <em>not <\/em>doing large scale development, then you may be tempted to include jQuery. I\u2019d ask you why. I recently did a code review for a junior developer, and this is essentially the code that they had written:<br><\/p>\n\n\n\n<pre><code>\n&lt;script type=\"text\/javascript\" src=\"jquery3.1.0.js\"&gt;&lt;\/script&gt;\n\nfunction hideButton() {\n   $(\u2018#submit-form\u2019\u2019).hide();\n}\n<\/code><\/pre>\n\n\n\n<p>That code is troubling for a number of reasons, not least of which is how simple it would be to write without jQuery.<\/p>\n\n\n\n<pre><code>\nfunction hideButton() {\n    document.getElementById(\u2018submit-form\u2019).style.display = 'none\u2019;\n}\n<\/code><\/pre>\n\n\n\n<p>The code runs faster and more efficiently, doesn\u2019t import a local library, works in all current browsers, and should be completely understandable to anyone familiar with the DOM. If you always use jQuery and swipe code from Stack Overflow, you\u2019ll never become familiar with the DOM. Maybe you\u2019ll use methods like children() or parent(), and write query selectors like <em>$(&#8216;#myButton&#8217;)<\/em>, but all of those are available to you in vanilla JS.<\/p>\n\n\n\n<p>My feelings about jQuery probably would not be as strong if it was a more modularized library. As is, it\u2019s fairly monolithic, encompassing DOM manipulation and traversal, AJAX requests, animations, event handling, browser polyfills, and some various other utilities. Its prevalence over the years has spawned thousands of other JavaScript libraries that rely on it as a dependency. I shudder when I see a simple widget, like a sortable table, that has a small footprint of a few kilobytes on its own, depend on jQuery which, when minified, is 80 kb.<\/p>\n\n\n\n<p>So this is yet blog promoting vanilla JS. There&#8217;s never been a better time to learn JavaScript. Now there are a ton of programmers who actually understand how JavaScript should be written, browser support is much better, and even if you can&#8217;t take advantage of ES6 and ES7 features in all the browsers you are developing for there are plenty of great transpilers like Babel to transpile code for you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8230;I\u2019m not about to say jQuery was a mistake, but I do think using it on a new project in 2018 (or 2019, 2020, current year) likely is.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[7,11,12],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-web-design","tag-javascript","tag-jquery","tag-web"],"_links":{"self":[{"href":"http:\/\/nicholascbrown.com\/blog\/wp-json\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nicholascbrown.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nicholascbrown.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nicholascbrown.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nicholascbrown.com\/blog\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":4,"href":"http:\/\/nicholascbrown.com\/blog\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"predecessor-version":[{"id":29,"href":"http:\/\/nicholascbrown.com\/blog\/wp-json\/wp\/v2\/posts\/25\/revisions\/29"}],"wp:attachment":[{"href":"http:\/\/nicholascbrown.com\/blog\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nicholascbrown.com\/blog\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nicholascbrown.com\/blog\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}