Why I Don’t Use jQuery in Django Admin

I’ve made a lot of customizations to Django admin using JavaScript. Although Django admin supports jQuery and will continue to do so in Django 4.0, I stick to vanilla JavaScript, and I recommend that you do the same for two main reasons:

  1. Vanilla JavaScript is, for most things, just as easy to write as jQuery, and much more useful to learn as it can be used on sites that don’t support jQuery.
  2. Eventually, I believe, Django will dump jQuery. It hasn’t shown any signs of doing so yet, but as fewer and fewer developers know jQuery and vanilla JavaScript continues to improve, there will be natural pressure to drop it and rewrite the built-in widgets in pure JavaScript.

Why? Is jQuery Dead?

It is not dead in the sense that it is not being used anymore. It is still widely used. But it is dead in the sense that it’s no longer being actively developed.

When John Resig created jQuery in January, 2006, the world of browsers was a scary place. Microsoft Internet Explorer held 90% of the market, Firefox and Safari were just beginning to gain market share, and Google Chrome, which today is far and away the most popular browser, wouldn’t appear for almost three years (see Wikipedia for browser usage statistics). Different browsers followed standards to different degrees, and the standards themselves were still evolving rapidly. The W3C released the first draft specification of the XMLHttpRequest object, the original backbone of Ajax, in April, 2006, but all major browsers had already supported some degree of Ajax functionality for several years. They just did it in different ways.

This situation resulted in a nightmare for web developers, many of whom despised JavaScript. Code had to be branched with conditional statements that checked the browser for feature support:

if (thisFeatureIsSupported()) {
} else if (thisOtherFeatureIsSupported()) {
} else {
  alert('Sorry, this feature is not supported by your browser.');

It was ugly!

While many JavaScript libraries attempted to solve this problem, jQuery quickly emerged as the leader, and it remains the most widely used JavaScript library today, in large part because it is baked in to so many existing websites.

Problems jQuery Solves

jQuery was created to solve three major problems:

  1. Allow developers to write code in one way that worked on all major browsers.
  2. Make it easier to write Ajax applications.
  3. Make it easier to locate, modify, delete, and add elements to a web page via JavaScript.

On top of this, jQuery provided neat, easy-to-implement effects to make it easier for developers to make snazzier web pages.

The Situation Today

Today, most of the original problems that jQuery addressed have been solved by improvements to the JavaScript language and the agreement by web browser makers on a standardized version of JavaScript. As the following charts show, jQuery has largely fallen out of favor:

The Death of jQuery UI and jQuery Mobile

Two popular offshoots of jQuery were jQuery UI and jQuery Mobile, but they are both all but dead. The following screenshot shows a blog post from December 21, 2017: “jQuery UI blog post The final ominous sentence of the post is “jQuery UI and jQuery Mobile rely on contributions from the community and can only continue to exist with your help!”

No help has come.

Dumped by Bootstrap

Another bad sign for jQuery is that it has been dropped from Bootstrap 5, the hugely popular HTML, CSS, and JavaScript library.

It’s a Matter of Time

It seems to me it’s just a matter of time before Django also drops its built-in support for jQuery. Maybe in Django 5.0?

Written by Nat Dunn. Follow Nat on Twitter.