« Previous 1 2
New features in jQuery 3
III
Point One
Version 3.1, released not even one month after the release of version 3.0, works differently in one case: In version 3.0, the jQuery developers converted jQuery.ready()
and jQuery.fn.ready()
internally to the new Deferred objects. They therefore also passed onerror
s to the Rejection handler internally.
This caused a problem: If programmers supplemented a ready
handler in the usual way – that is, with either of
jQuery(function() { ... }) jQuery(document).ready(function() { ... })
they were then unable to register a Deferred handler. Consequently, they learned nothing from an error (silent errors). To make matters worse, before version 3.1 programmers weren't able to identify uniquely whether the new Deferreds were suddenly pottering about under the hood.
jQuery 3.1, on the other hand, reports errors on the console by default. Programmers can control the behavior using the new method jQuery.readyException()
. jQuery passes on any errors that occur in a ready
handler to this method:
jQuery.readyException = function(error) { // each ready handler throws errors };
To not block the execution of an application, jQuery.readyException()
throws the error asynchronously and writes it to the console.
Slimming Cure
The developers have offered a "slim" variant of jQuery since version 3.0. It is missing the Ajax functions, the effects module, and the deprecated code. The minimized version of the slim variant (jQuery-3.1.0.slim.min.js
) is about 17KB smaller than the minimized normal jQuery 3 (jQuery-3.1.0.min.js
), which still carries plenty of weight at around 84.3KB.
Anyone wanting to upgrade from jQuery 2 to jQuery 3 should definitely read the jQuery Core 3.0 Upgrade Guide [7] beforehand. The jQuery developers also provide a Migrate plugin [8] on GitHub, which on the one hand issues a warning if you access functions that no longer exist in jQuery 3 or are considered deprecated. On the other hand, it simulates the behavior of jQuery 2, thus making it possible to revise web applications gradually.
Anyone who uses a framework such as Bootstrap [9] or a CMS like Joomla [10] needs to investigate which jQuery versions they use, because they often cannot be changed readily.
Conclusions
jQuery 3 is a logical development of version 2. The changes are limited, and the developers have discarded some of the code that has been deprecated for a while. So heaving a web application onto jQuery 3 shouldn't require that much work. However, with the minimized version at almost 85KB, jQuery 3 is still a hefty chunk. The jQuery team is now focused on further developing jQuery 3. However, the old versions 1.12 and 2.2 still receive bug fixes, so developers can address the migration in peace.
Infos
- jQuery: https://jquery.com
- jQuery distribution: https://w3techs.com/technologies/overview/javascript_library/all
- jQuery 3.0: https://blog.jquery.com/2016/06/09/jquery-3-0-final-released/
- jQuery 3.1: https://blog.jquery.com/2016/07/07/jquery-3-1-0-released-no-more-silent-errors/
- Promises/A+ Compliance Test Suite: https://github.com/promises-aplus/promises-tests
- jQuery Deferred Reporter plugin: https://github.com/dmethvin/jquery-deferred-reporter
- jQuery Core 3.0 Upgrade Guide: https://jquery.com/upgrade-guide/3.0/
- Migrate plugin: https://github.com/jquery/jquery-migrate#migrate-older-jquery-code-to-jquery-30
- Bootstrap: https://getbootstrap.com
- Joomla: https://www.joomla.org
« Previous 1 2
Buy this article as PDF
(incl. VAT)
Buy ADMIN Magazine
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Most Popular
Support Our Work
ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.