preface
A few days ago, THERE was a question: is jQuery really obsolete? My answer is: jQuery is obsolete! I thought it was an interesting topic, so we had a chat. Explain in detail why jQuery is obsolete.
What pain points jQuery solves
When discussing whether a library or framework is obsolete, one should first look at what problems it solves and whether there are better solutions for those problems now.
What problems does jQuery solve?
Browser Compatibility Issues
IE678 era, browser compatibility problem is the front-end partners must master the skills, IE6 bugs, this has to back such as flow. IE does not recognize which standard JavaScript methods and objects, this also have to remember, write ajax, others use XMLHttpRequest, to IE use ActiveXObject. Helplessly painful front-end programmer cannot concentrate on research technology, can wipe ass for browser manufacturer everyday only. Until jQuery came along, we were free. Whether it was DOM manipulation, event binding, or Ajax, jQuery gave us a way to encapsulate all browsers, and the whole world was at peace.
The selector
Without jQuery, we get DOM objects using methods like getElementById and getElementsByTagName. Bind events for all elements of the list, either event delegate or iterate over all elements. We’ve mastered all sorts of weird tricks to get the fucking DOM interface right, but they don’t really work. With jQuery, you can retrieve elements using CSS selectors, and binding events don’t need to be traversed through the list of elements.
Animation effects
I remember vividly the first time I wrote an animation with a timer, how to make an element move and how to make it stop moving. After debugging, no bugs, this is a bunch of code, let alone a complete page effect, just think of it. After looking at the animation effects jQuery provides, it’s hard to imagine how we could achieve the desired effects in IE678 without jQuery.
conclusion
JQuery addresses more than that: its DOM manipulation, style manipulation, attribute manipulation, event binding, traversal, form serialization, and Ajax encapsulation bring a whole new world of front-end development. To this day, jQuery is still the most used library by front-end developers.
2. An alternative to jQuery
JQuery’s impact on the front end is unprecedented, but with the development of the front end, jQuery has become obsolete, and there are alternatives to the pain points it solves for us.
Browser compatibility
Browser compatibility is becoming less and less of an issue, and IE6 has been phased out (currently only XP systems in large state-owned enterprises, public institutions, government offices and hospitals still have IE6, but it is also being phased out). Tmall announced last year that it would no longer support IE8. Browser compatibility issues still exist, but it’s not the same era.
The selector
CSS3 has added a large number of selectors, manipulation style, you can find as you like, do not bother to jQuery.
Native JavaScript also adds querySelector and querySelectorAll methods to retrieve elements directly from CSS selectors.
Animation effects
Css3 provides rich transitions and animations that don’t rely on jQuery.
ajax
Third-party modules such as Fetch and Axios have encapsulated Ajax so well that we no longer need to introduce jQuery just for a $. Ajax.
DOM manipulation and event binding
Aside from the animation problem, the remaining is mainly the increase, deletion and change of data, this operation with jQuery, no matter from the point of view of performance, or easy to develop and maintain, the MVVM framework is much more than jQuery.
Componentization and modularization
Componentized and modular development is the mainstream of front-end development, the advantages of simple is easy to develop, easy to maintain, easy to team division of labor.
JQuery can be componentalized, but writing components in jQuery can be described in two words: pain in the ass, who knows?
ES2015 (import,export), webpack (require,module.exports), etc
From what has been discussed above
For all the advantages of jQuery there is a better solution, it is safe to say that jQuery is obsolete!
(If your company requires IE678 compatibility, that’s a different story.)
JQuery is not obsolete
JQuery is obsolete, but it’s not obsolete, and it won’t be for years.
Most of the websites and applications on the market today are still based on jQuery, and they will need to be maintained in jQuery for years to come. Many companies don’t have a dedicated front-end developer, they do front-end work in the backend, and they prefer to use jQuery plus background templates. Some of them have more than two or three years of experience in front-end development. They are satisfied with the status quo, reject the new features of CSS3, and have no patience to learn the MVVM framework. JQuery is still their main tool. IE678 hasn’t gone away, so jQuery still has a place. JQuery is easy to get started and still great for simple websites.
To sum up, jQuery has not been eliminated and is still a must-have skill for newcomers.
Four,
JQuery may be out of date, but it’s still a must-have skill for front-end development.
Five, the end
If you feel that there is a harvest, please do not begrudge a small [praise], if you like similar articles, you can follow the wechat public number: [Xiaozhou Report], the first time to get the article.