[POC] Remove jQuery dependency, use vanilla JS#4450
Conversation
Ports all of js/*.js to vanilla DOM APIs: - dlang.js: navigation/menu toggling - ddox.js: symbol search - listanchors.js: version selector - platform-downloads.js: download button injection - show_contributors.js: fetch contributors list (XHR -> fetch()) - run.js: runnable example boxes ($.ajax -> fetch()) - run_examples.js: per-unittest runnable boxes Drops the jquery CDN/local <script> tags from dlang.org.ddoc and book/dlang.org.ddoc, removes jquery-3.7.1.min.js, and trims the posix.mak JAVASCRIPT list. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
|
But why? |
|
Presumably to prevent further dependabot alerts. Came up in #4449 (review) @0xEAB I was wondering if jQuery was pulling its weight as a dependency, but this diff is quite large, so maybe it is. |
That’s obviously to be determined. If it serves good use, we sure can keep it. But often it’s a relict from times when cross-browser JS was a serious problem and it surely helped with that. These days it’s rarely used for new projects and even Bootstrap dropped jQuery as a dependency (it is still supported as an optional add-on). |
Considering that we're building and deploying a static website with no user-generated content, I'm wondering if in this case it is dependabot who is not pulling its weight. 🤔 |
I'm not a fan of Javascript frameworks, and jQuery to me is just 10000 lines of imported bloat and obfuscation, so I'm also in favor of removing it. But I'm not going to put work in this if it's controversial. Aside from the raw AI translation, are you against this idea in principle @CyberShadow ?
Did we explicitly enable that? Should we disable it? |
|
No, the only reason why I'm slightly in disfavor is that it adds more code than it removes, so overall it increases our code's complexity.
Not sure, but there might be a middle ground, e.g. only updates that are security sensitive, which should reduce their frequency. Letting an AI screen updates for those relevant to us also seems to be an emerging practice. |
- run.js: drop unreachable dpaste backend (tour.dlang.org has been the only backend since commit 58e80ca; dpaste.dzfl.pl no longer resolves). Collapse the backends/safeVar/parseOutput indirection into a single runOnTour() helper. - run_examples.js: drop reformatExample (only call site was commented out) and the stale backend: "tour" option now that there is one. - platform-downloads.js: drop the broken IE polyfill (getElementsByTag is a typo; document.currentScript is universally supported) and the always-false model == null branch. - ddox.js: drop searchCounter (set but never read). - dlang.js: replace the closestMatching helper with Element.closest(). - Trim a stale top-of-file workflow comment in run.js that referenced long-removed md5sum machinery. No behavior changes beyond the dead-code removals. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
That’s kinda expected, given an utility library was replaced with vanilla code. |
|
OK, no objection from my side. Too bad we don't have any E2E tests that could validate this at least a little.
This is useful, anyone tried going through this? I guess CI is still building the site. |
Okay, then I'll see if I can do a manual audit and test of the code, and then I'll mark the PR ready.
Something like Playwright? |
Yes, exactly. E.g.: https://github.com/CyberShadow/DFeed/commits/master/tests |
An experiment based on #4449 (review), just to see what it looks like. Haven't reviewed it manually yet, opening just for CI and illustration purposes to begin with. Is this actually a good thing to do?
Claude's description:
Summary
Removes the jQuery dependency entirely. All seven scripts under
js/are ported to vanilla DOM APIs:dlang.js— nav/menu togglingddox.js— symbol searchlistanchors.js— version selectorplatform-downloads.js— download button injectionshow_contributors.js— contributors list (usesfetch())run.js— runnable example boxes (usesfetch()for the run backend)run_examples.js— per-unittest runnable boxesAlso drops the jQuery
<script>tags fromdlang.org.ddocandbook/dlang.org.ddoc, removesjs/jquery-3.7.1.min.js, and trims theposix.makJAVASCRIPT list. Net result: one fewer CDN dependency and ~87 KB minified jQuery removed.Targets the same target browsers that already loaded jQuery 3.7.1 (modern evergreens; IE not supported).
Test plan
[hide]/[show]toggle on a Phobos pagelibrary/)std.algorithmstd.*