Javascript frameworks are really powerful, when you need them
You can also be interested in:
Introduction
I've always used some kind of javascript framework when developing frontend stuffs. Mootools, jQuery, extjs and friends. All such frameworks provide a set of useful functionality, but above all in my opinion, they provide what is crucial for a web developer: cross browser compatibility.
The time you'll spend in writing cross browser code, even for a small project, is huge, especially if your software must support IE<9, and especially at the beginning, since you need to learn all browser inconsistencies.
But sometimes your script doesn't need to be cross browser, or its implementation includes functionality which do not suffer browser compatibility issues. In such case even if we are accostumed with the framework syntax, and we have it loaded in the page, can be better to use vanilla js to complete some tasks.
And the (main) reason is one: performance.
An example
Let's consider one common operation, for example we need to change the src attribute of an image inside a div#meow. We could use the mootools or jQuery selectors functions to retrieve the image element and change its src attribute, or we could use vanilla js. This is a case which shouldn't suffer of browser inconsistencies.
Who uses to use a framework, probably will use its selectors functions to achieve such result. But is this really a good choice?
In my opinion it isn't. Or better, it is not a good choice if all we need to do is to change the src attribute of the image.
Let's consider mootools; the point here is: why should we instantiate a mootools Element object if we really need only to change the src attribute?
The mootools selector returns a mootools Element object which is supplied of all the Element methods that the library provides. This is good if we have to work a lot with it, if we have to attach events for example (events represents one of the cross browser issues), but all this methods are useless if we only really need to change the src attribute, got it?
I've written one simple test in codepen.io, which I include here. Depending on your browser you may see different numbers, but the result sholud be clear.
See the Pen selector performance comparison, vanilla VS mootools by abidibo (@abidibo) on CodePen.
Summary
If your js code doesn't need to be cross browser, or if you are developing some functionality which don't suffer of cross browser inconsistencies, ..., actually if you don't need all the enhancements that the library provides, go vanilla js.
Your Smartwatch Loves Tasker!
Your Smartwatch Loves Tasker!
Featured
Archive
- 2021
- 2020
- 2019
- 2018
- 2017
- Nov
- Oct
- Aug
- Jun
- Mar
- Feb
- 2016
- Oct
- Jun
- May
- Apr
- Mar
- Feb
- Jan
- 2015
- Nov
- Oct
- Aug
- Apr
- Mar
- Feb
- Jan
- 2014
- Sep
- Jul
- May
- Apr
- Mar
- Feb
- Jan
- 2013
- Nov
- Oct
- Sep
- Aug
- Jul
- Jun
- May
- Apr
- Mar
- Feb
- Jan
- 2012
- Dec
- Nov
- Oct
- Aug
- Jul
- Jun
- May
- Apr
- Jan
- 2011
- Dec
- Nov
- Oct
- Sep
- Aug
- Jul
- Jun
- May