django / django/djangoproject.com

Proposal for further front-end cleanups

Open
#1,827 14 comments 1 reaction 1 assignee Claimed by @adamzap View on GitHub
Dominant language
Python
Stars
2k
Forks
1.1k
Avg merge
3d 10h
Merged PRs (30d)
33

Description

I'm curious if the maintainers would accept pull requests for the following front-end changes. Some of these ideas are more opinionated or need more guidance than my previous PRs, so I wanted to get feedback first.

## ~~Remove `bower`~~ (#1830/#1832)

As its website says, [`bower`](https://bower.io/) is maintained but not recommended for use by its developers. [Our `bower.json`](https://github.com/django/djangoproject.com/blob/ff2fd01/bower.json) file now only includes two dependencies: `jquery` and `jquery-flot`.

Instead of using `bower`, could we instead put `jquery.min.js` and `jquery-flot.min.js` directly in [`djangoproject/static/js/lib/`](https://github.com/django/djangoproject.com/tree/ff2fd01/djangoproject/static/js/lib)? This would include removing the `jquery` and `jquery-flot` directories.

## Remove `require.js`

[`require.js`](https://requirejs.org/) had a small security release in July 2024, but the release before that was in 2018, and [the project is not under active development](https://github.com/requirejs/requirejs/issues/1854#issuecomment-2049998599). I'm still trying to understand the full influence that `require.js` is having on this project, but removing it would require at least the following changes in addition to removing the library itself:

1. Remove [the setup for `require.js` in the `base.html` template](https://github.com/django/djangoproject.com/blob/ff2fd01/djangoproject/templates/base.html#L137-L167)
2. Remove the `define` calls in our JavaScript modules ([example](https://github.com/django/djangoproject.com/blob/ff2fd01dba5de6b0d641e86df9bba64f4770e8f9/djangoproject/static/js/mod/clippify.js#L1))
3. Remove or repurpose [`main.js`](https://github.com/django/djangoproject.com/blob/ff2fd01/djangoproject/static/js/main.js)
- **Option 1**: Remove the file and add `` tags to the templates where needed. Adding a new template block for JavaScript includes would also be a good idea. *This approach is simple but is riskier and requires more work and testing, but it's the one I would choose.*
- **Option 2:** Keep the file for its class-based logic and dynamically add `<script>` tags to the DOM based on it. *This approach requires less changes and may be a good way just to remove `require.js` without broader changes.*

Which approach would be preferred here, or is there a better way than what I presented above?

## Remove Boilerplate in Many JavaScript Modules

[Many](https://github.com/django/djangoproject.com/blob/ff2fd01dba5de6b0d641e86df9bba64f4770e8f9/djangoproject/static/js/mod/console-tabs.js) of [our](https://github.com/django/djangoproject.com/blob/ff2fd01dba5de6b0d641e86df9bba64f4770e8f9/djangoproject/static/js/mod/doc-switcher.js) JavaScript [modules](https://github.com/django/djangoproject.com/blob/ff2fd01dba5de6b0d641e86df9bba64f4770e8f9/djangoproject/static/js/mod/mobile-menu.js) define an enclosing function then add an `init` method to its prototype. This is where the actual logic lives. It seems to me that we could decompose these and just run everything in the top-level enclosing function. Perhaps the current pattern is related to `require.js`?

Could these modules be simplified, or is this kind of refactor too unnecessary?

## Upgrade or Remove `jQuery`

We're currently using [jQuery v1.11.2](https://github.com/django/djangoproject.com/blob/ff2fd01dba5de6b0d641e86df9bba64f4770e8f9/djangoproject/static/js/lib/jquery/dist/jquery.js#L2), and the latest release is [v3.7.1](https://jquery.com/). Jumping ahead through ten years of releases could be a pain, but I think it's worth it if jQuery is valued in this project.

Another option would be to remove `jQuery` instead. We could convert one module at a time to native browser APIs before its removal. Doing this would probably force a replacement of `jquery.flot` for the `dashboard` app.

## Integrate a JavaScript Linter/Formatter

I'd be willing to work on this, but I'd want guidance on which tool to use and the settings for it.

---

Thanks for considering these!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.