The life without the jQuery

The most used framework

Ask any web developer which JS library is the most used. Bet the answer will be “jQuery”. More than 700k questions on StackOverflow, 38+k stars on GitHub, they say for itself.

Moreover, a lot of ‘so called web developers’ know jQuery better than native JS. I don’t judge ’em, jQuery provides really convenient way of handling the content of the page.

History

Analyzing the history, there were two killer features of the framework:

  • $() selector mechanism (Sizzle), and
  • cross-browser support.

The first feature allowed accessing elements using CSS principles and this is not only usual and convenient but way simplier than native

.getElementById() / .getElementsBy{...}Name();

and

.children[] / .parentNode;

The second feature made us forget all the peculiarities of our favorite browser of 6th, 7th and 8th versions.

That are not the only features jQuery was famous for. Remember chaining

$('.toggle').parent().addClass('collapsed').children('.header').html('Expand');

single method for setting/getting the property (.htlm() vs. .html('test')), AJAX and Deferred implementation and many many more.

So what’s wrong with jQuery?

Nothing actually wrong with this library, it’s great. And I want to attract your attention to several points:

  • there is year 2016 outside and the Web has changed significantly. You hardly meet the issue of cross-browser support unless you dig really deep or the karma punishes you by supporting IE8/9. W3C standards rule the world all the modern browsers support declared features in pretty standard way.
  • A lot of jQuery-specific features are supported by default by browsers: .querySelector() / .querySelectorAll(), $.Deferred vs. Promise.
  • CSS3 helps you with tons of pretty interface things (animation, collapsing/expanding and so on ā€• they used to be done with jQuery).

One more thing to mention, but it’s rather about developers that about jQuery. Analyzing the code I often see using only the couple of methods in whole project. My question is:
“Do you really need 80+k library for only these five methods?”

Is there life without jQuery?

Well, let me share the experience of last three years. Two big projects I was involved into use ExtJS and React respectively. There were couple of small projects and only one of ’em uses jQuery. All the other use ZeptoJS and custom HTML handling libraries.
I can say “Yes, I survived three years without jQuery.” It’s doable šŸ™‚

How it’s possible?

Speaking about contemporary frameworks, we observed a big evolution during last 5 years. Say in the end of previous decade JS frameworks started dancing from the HTML representation (HTML-centric). On the other hand, contemporary frameworks move data towards HTML (data-centric). Well, some of ’em don’t really care about the representation layer. For instance, the Flux/React allows you to replace the native JSX/HTML renderer with, for instance, PixiJS for WebGL or SnapSVG or a Canvas2d library.

Contemporary frameworks don’t usually use direct HTML access (that’s usually the anti-pattern). Say when you design the element in ExtJS, you have special wrappers for doing all the DOM things you actually need. Moreover, the generated HTML looks sometimes unusual (a lot of wrappers around the element).
Flux/React architecture makes you to ‘build-and-forget’ the HTML (actually the JSX); after that you don’t care about the data: once you change something in the Store, Views are updated automatically.

Ok Google, what should I do?

Use your own head. Analyze your project, choose the framework you’ll use and start building the application. You’ll see, will you need the jQuery or won’t you.

Once you see the unavoidable necessity of handling the DOM directly, mind following:

  • if a couple of simple things like adding/removing a classname is everything you need, write some helpers by yourself.
  • If your project requires some hard stuff, try Zepto. It’s way smaller and almost as mighty as jQuery.
  • Try custom builds of jQuery. Include only those modules you really need.

Well, eventually if you see a library you need requires jQuery explicitly, go ahead and use it šŸ™‚


May the force be with you, JS warrior!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s