Skip to content

Load the page scripts after the first paint (#63, stacked on #304) - #313

Open
r0ny123 wants to merge 40 commits into
masterfrom
perf/load-scripts-after-first-paint
Open

r0ny123 wants to merge 40 commits into
masterfrom
perf/load-scripts-after-first-paint

Conversation

@r0ny123

@r0ny123 r0ny123 commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #304 (and so on #245 and #126). Merge those first; until then this diff also shows their commits. This PR's own commits are 9847aa0 and 5fcb0c5, with 6a0e0d7 and 5ba7515 since.

Part of #63. #304 defers jQuery, so no script in <head> holds back the first paint. A deferred script is still fetched at once, though, alongside the stylesheets the page is painted with: jQuery, post_action.js, page_loading.js, the type-ahead, a page's own jQuery plugins and Bootstrap's bundle share the first round trips with the CSS. This branch fetches them once the page has been painted.

Change. In base.html's first script:

  • later(src) (:54) queues a script. base.html queues jQuery (:133), post_action.js, page_loading.js and autocomplete.js (:153-:155), and Bootstrap's bundle below {% block style %} (:190). result_cross.html:72 queues jQuery UI and settings.html:10 SortableJS from that block, so they run after jQuery and before Bootstrap, as their deferred tags did.
  • The queue starts once the browser reports the first contentful paint (PerformanceObserver, :121). A browser without paint timing starts it from a timer set in requestAnimationFrame; a page that is not visible starts it at once (:118); and if nothing has started it three seconds after DOMContentLoaded, a timer does (:130). startTheQueue() (:112) starts it once.
  • loadTheQueue() (:90) adds the scripts with async = false, which runs them in the order they were queued, however they arrive.
  • whenReady(fn) (:58) keeps fn until the queue has run. Then queueHasRun() (:80) replaces it with one that hands fn to jQuery's ready queue, hands it everything kept, in order, and makes the held presses again.
  • A click on a data-bs-toggle, data-bs-dismiss or data-post element before then is held (holdEarlyPress, :70) and made again once the queue has run. On Defer jQuery, and run the inline code that needs it from whenReady #304 such a click did nothing. A tooltip toggle is not held: a tooltip is shown on hover and focus, and with Establish UI/UX parity and design consistency across views #253 the copy button carries data-bs-toggle="tooltip" next to its own onclick.
  • csrfToken() (:64) moves here from post_action.js: the CFG viewers call it from window.onload, which can come before the queue has run.

Elsewhere:

  • js/ac_family_names.html:11 waits in whenReady instead of DOMContentLoaded, which now comes before the queue.
  • table/submit_or_query_dropzone.html:42: the upload form's ready handler sets its fields with show() and hide() instead of sliding them. It runs after the first paint now, where a slide is a layout shift on the upload pages, and on every other page 400 ms of animation of the closed drop overlay's form.
  • table/links.html:69: copy_to_clipboard copies at once and shows its "Copied!" tooltip from whenReady. Pressed before jQuery had run, it copied and then threw "$ is not defined", on Defer jQuery, and run the inline code that needs it from whenReady #304 too.
  • ADR-0021 records the queue. ADR-0018's status and AGENTS.md's front-end rule now point at it, and AGENTS.md's CSRF rule names csrfToken()'s new place.

Verification. On the testbed, #304's head (901ac33) and this branch ran as side instances against the live backend, logged in as analyst1. Apart from the logins and the CFG pages' own POSTs to /explore/findLoops/, every request to MCRITweb was a GET; of its calls to the backend, the only POST was the /samples/ids lookup, a read. The measurements are of 389350d. The head adds the tooltip toggle's exception to holdEarlyPress and its test, and changes two lines of ADR-0021 and one of AGENTS.md; no Lighthouse run presses anything.

Lighthouse 12.8.2, mobile, two runs a side, the sides in turn. Performance is given for each run; the rest are means.

page Performance FCP LCP TBT CLS
/ 96/97 -> 98/98 1.42 -> 1.40 s 2.62 -> 2.30 s 24 -> 9 ms 0.000 -> 0.000
/explore/samples 91/91 -> 94/95 1.85 -> 1.87 s 3.20 -> 2.77 s 39 -> 24 ms 0.000 -> 0.000
/explore/samples/1 93/93 -> 95/95 1.86 -> 1.86 s 3.04 -> 2.70 s 16 -> 26 ms 0.000 -> 0.000
1vN result 83/85 -> 85/85 2.75 -> 2.76 s 3.78 -> 3.64 s 28 -> 22 ms 0.000 -> 0.000
cross result 83/92 -> 93/94 1.87 -> 1.86 s 3.44 -> 2.72 s 175 -> 133 ms 0.000 -> 0.000
unique-blocks result 90/90 -> 94/93 1.99 -> 1.99 s 3.34 -> 2.89 s 31 -> 18 ms 0.000 -> 0.000
jobs 94/94 -> 96/96 1.55 -> 1.70 s 2.90 -> 2.60 s 44 -> 5 ms 0.000 -> 0.000
/help 89/91 -> 94/93 1.55 -> 1.54 s 3.54 -> 3.11 s 30 -> 20 ms 0.000 -> 0.000

On a build of master with #126, #245, #304 (at 63b75c7, which differs from its head only in the ADR's text), #253, #302, #303, #160, #291, #268, #292, #306, #307, #308 and the Bootstrap cut (#309), against the same with this branch's changes carried over by hand (the same first script, queued libraries, type-ahead, upload form and copy button):

page Performance FCP LCP TBT
/ 99/100 -> 100/100 0.95 -> 0.96 s 1.80 -> 1.30 s 23 -> 18 ms
/explore/samples 99/100 -> 100/100 1.09 -> 1.10 s 1.70 -> 1.43 s 41 -> 62 ms
/explore/samples/1 99/99 -> 100/100 1.28 -> 1.27 s 1.92 -> 1.27 s 18 -> 9 ms
1vN result 98/98 -> 100/100 1.41 -> 1.42 s 2.16 -> 1.42 s 49 -> 2 ms
cross result 99/99 -> 99/100 1.25 -> 1.27 s 1.84 -> 1.34 s 56 -> 86 ms
unique-blocks result 99/99 -> 100/100 1.09 -> 1.08 s 1.91 -> 1.40 s 29 -> 26 ms
jobs 100/99 -> 100/100 0.93 -> 0.94 s 1.79 -> 1.26 s 12 -> 5 ms
/help 97/98 -> 99/99 1.10 -> 1.10 s 2.43 -> 2.03 s 18 -> 24 ms

CLS is 0.000 on both sides of every build row except the 1vN result's, which is 0.001 on both. #304 has no viewport meta tag (#253 adds it), so its Best Practices score is 93 on both sides, and the build's is 100.

What a real browser shows is less. A browser review, on the branch before the copy button's change and the tooltip exception, timed nine pages on both sides in Chromium throttled to 1.6 Mbps down, 150 ms round trips and a CPU four times slower, three runs a side (medians, base -> branch, five of the nine shown):

page first contentful paint every whenReady handler run
/explore/samples 1348 -> 1284 ms 1861 -> 2419 ms
/ 1044 -> 1016 ms 1624 -> 2005 ms
settings 1052 -> 1012 ms 1817 -> 2163 ms
jobs 1600 -> 1596 ms 2091 -> 2422 ms
a function 1184 -> 1180 ms 2892 -> 3077 ms

First paint comes 0 to 120 ms earlier, and the page is ready 75 to 560 ms later on most pages. Lighthouse simulates the load from what it observed and counts every request that started before a paint against it; a real browser on a slow link was already painting before the deferred scripts arrived. ADR-0021 records both. What the readiness costs is offset where a press would have been lost: the same review held jquery.js back on both sides and pressed the navbar menus, the mobile navbar toggler, a modal opener, a settings tab, an alert's close button, Tab and Enter on a menu, and a data-post button. #304 dropped every press. The branch made each one once it was in, in order, and the data-post button sent one POST (aborted by the review). Loading 27 pages once a side, unthrottled at 1440 and 390 px, it found no page error and no console error on either side, and the same scripts requested; full-page screenshots once ready were identical, apart from the server page's backend port and a few pixels that also differ between two runs of one side. Re-run on this branch's head, five runs a side: the families page's screenshots are identical on all ten; on a family and on the search page they vary between runs of either side, and the branch's include the one #304 gives most often. The Tab order is the same over 45 stops on the samples, function and settings pages. With Dumped picked before jQuery was in, #304 slid the upload pages' fields over 23 and 22 frames, with 14 and 7 layout shifts; the branch set them within 3 and 0 frames, with none.

Tests. In tests/testDeferredJqueryBrowser.py, in Chromium against the captured corpus:

  • test_the_queue_is_fetched_once_the_page_has_been_painted: every queued script's request starts after the first-contentful-paint entry, and the scripts run in the order queued, read from their load events. The order the requests start in is not checked: the browser need not keep it, and under load it did not.
  • test_a_page_that_is_not_visible_loads_the_queue_without_painting, test_without_paint_timing_an_animation_frame_starts_the_queue and test_a_page_that_reports_no_paint_loads_the_queue_after_three_seconds: each start, timed from DOMContentLoaded, with the other starts taken away.
  • test_the_queue_is_loaded_once: 3.5 s after the page is ready, jquery.js has been requested once.
  • test_when_ready_after_the_queue_has_run_runs_at_once.
  • test_the_csrf_token_is_there_before_the_queue_has_run.
  • test_a_press_on_a_navbar_menu_before_bootstrap_is_in_opens_it_once_it_is and test_a_press_on_a_post_button_before_post_action_is_in_posts_once_it_is, with jquery.js held back.
  • test_the_upload_form_is_set_without_a_slide_at_load[contributor-/analyze/query|visitor-/explore/samples]: no jQuery animation runs at load, and the extended fields are shown or hidden as the checked radio asks.
  • test_a_copy_pressed_before_jquery_is_in_copies_and_confirms_once_it_is, and test_a_press_on_an_element_with_a_tooltip_is_not_held: the copy button marked up as Establish UI/UX parity and design consistency across views #253 marks it still copies on the press itself.
  • The existing tests wait for whenReady, with a timeout, instead of jQuery's ready, which no longer exists at load.

tests/testPageAssets.py checks the queue's order (jQuery first, the page's plugins before Bootstrap, Bootstrap below {% block style %}) and that no template has a defer tag. tests/testParseTimeScripts.py's scanner counts a DOMContentLoaded, load or pageshow listener and window.onload as code that runs before the queue, with cases for each. tests/testDropzoneBrowser.py and tests/testAutocompleteEscaping.py waited for load before acting on the page; they wait for whenReady now.

Taking a piece of the change out makes a test fail. The pieces are: the hidden page's start, the animation-frame start, the three-second backstop, the guard that starts the queue once, starting the queue at DOMContentLoaded, async = false, the replay, csrfToken() in base.html, leaving whenReady unreplaced, the scanner's listener and onload rules, a $ in a DOMContentLoaded listener, a defer tag, the slide at load, the old copy_to_clipboard and the tooltip toggle's exception.

The gate counts six tests in the two testPageAssets.py classes this branch edits, the cross compare's and the jobs page's, as new; the branch does not change them, and they pass on #304 as before.

Relation to open PRs. A trial merge (git merge-tree) with each open PR head adds no conflict: #160, #176, #264 and #266 conflict with this branch in the same files, and in as many hunks, as they do with #304. #130, #253, #254 and #293 are on master now, and their conflicts are resolved in the merge of master below.

Master 8fd5a8c is merged in (bfaf52b), with two adaptation commits: db16cb9 queues #293's search as you type after the first paint, and 61d8021 regenerates the icon subset for master's new icons.

r0ny123 added 28 commits August 30, 2026 04:44
Issue #63, first bullet: "remove data-tables js/css once it is not needed
anymore". base.html loaded 623 KB of render-blocking JavaScript and 41 KB of
CSS on every page in the app, for two calls.

DataTables is removed outright, not moved. Its one initialiser selected
`#job-table`, and the jobs page renders its table with `table_id=active` -
the job method - so the selector matched nothing on every request. Confirmed
against the running app: `id="job-table"` appears in zero of /data/jobs,
?active=..., ?state=... and /. It was also configured with paging, searching
and info all off, so even where it had matched it would only have restyled
the table.

jQuery UI moves to result_cross.html, the only page that calls `.sortable()`.
{% block style %} runs after base.html's scripts, so jQuery is in place first.

Measured with Chromium, total decoded bytes per page:

    /                     1667 KB -> 1017 KB
    /explore/samples      1667 KB -> 1017 KB
    /data/jobs            1667 KB -> 1017 KB
    /data/result/<cross>  1691 KB -> 1595 KB   (keeps jQuery UI)

Behaviour is unchanged: `.sortable()` still applies on the cross compare, the
clipboard tooltips still get Bootstrap instances rather than jQuery UI's -
both libraries define `.tooltip()`, and removing jQuery UI makes which one
wins deterministic rather than a load-order race - and no page logs a console
error.

Deliberately not done: `defer` on the remaining scripts, and removing jQuery.
Both need an audit of 23 inline blocks and 36 onclick handlers, several of
which call functions declared at the top level of those blocks; that is a
separate change. The remaining majority of the render-blocking weight is CSS,
not JS - bootstrap.css alone is 196 KB and is the unminified build.
Every unit job on every Python version fails with:

    /opt/hostedtoolcache/Python/3.11.16/x64/bin/python: No module named pytest

The Makefile said "pytest and pytest-cov arrive with mcrit, so requirements.txt
covers both". mcrit declares them under its `dev` extra:

    $ python -c "import importlib.metadata as m; print(m.requires('mcrit'))"
    ... 'pytest; extra == "dev"', 'pytest-cov; extra == "dev"' ...

so a plain `pip install -r requirements.txt` does not bring them in, and the
suite has not actually run in CI since mcrit moved them there. Ruff is green
throughout, which is why this looked like a working pipeline.

Installed in the workflow rather than added to requirements.txt: neither is a
runtime dependency and a deployment should not get them. Pinned, for the same
reason the lint job pins ruff. The two stale comments that said otherwise are
corrected.
`init` still ran `pip install -r requirements.txt` alone, so a fresh checkout
that follows the README lands without pytest and `make test` fails with
"No module named pytest" - the same failure the CI change on this branch fixes
for the runner, left unfixed for a contributor.

pytest and pytest-cov are not runtime dependencies and are not in
requirements.txt; mcrit declares them under its `dev` extra, which nothing
here requests, so they do not arrive transitively either. Install them from
`init`, pinned to the versions CI uses, and say so once above the target
rather than in a comment further down that describes a step that never ran.

Reported by Codex review.
…rst one was safe

The previous commit did #63's first bullet. The other four are "consider", "enable
text compression" and "what to inline"; a recorded, measured decision is the
resolution for those, so ADR-0015 makes them. Numbers first, all from Chromium
driving the app over real HTTP against the captured corpus.

  * text compression is the largest win left, and it is not ours. Nothing is
    compressed anywhere: Flask's static handler does not, and neither does the
    reference deployment - nginx.conf, mcritweb_plain.conf and mcritweb_ssl.conf in
    danielplohmann/docker-mcrit at 7e9501a carry no gzip directive, and location /
    proxies /static/ straight through. Simulating `gzip on;` in front of this branch,
    cold Fast-3G load of /, median of 7: first paint 3872 ms -> 1024 ms, wire
    1,069,548 B -> 354,002 B. That is more than the whole of the first bullet, and it
    belongs in docker-mcrit.

  * lazy dropzone: right target, wrong shape today. dropzone.js is 353,924 B, 38% of
    every page, but it loads at the end of <body>, so blocking it outright - an upper
    bound - moves first paint by 8 ms. It buys DOMContentLoaded (1585 -> 1009 ms) and
    23% of the transfer. The cost is Flask-Dropzone: dropzone.config() emits
    Dropzone.options.myDropzone *after* the library and only works because discovery
    waits for DOMContentLoaded. Injected late, contentLoaded() sees readyState
    "complete" and binds the element with default options - no CSRF header, no
    autoProcessQueue: false. Doing it right means replacing create()/config() by hand
    in the one place static/dropzone.js's local patch has to keep working.
    "autocomplete on mouseover" is 4,621 B, 1,507 gzipped: no.

  * removing jQuery: no. 15 of 26 inline blocks call $, 36 inline event attributes
    hang off them, trace_CFG/main.js and main_duo.js expect it from base.html, jQuery
    UI cannot load without it, and .tooltip()/.modal() go through Bootstrap's jQuery
    bridge. 89,503 B, 30,882 gzipped - under 9% of a compressed page.

  * inline vs reference is already right: 7,141 B of inline JS against 902,940 B of
    referenced library. The remaining CSS weight (bootstrap.css is the unminified
    build) compresses 8x, so gzip answers that too.

ADR-0004 asked #63 to assert rather than assume which library owns $.fn.tooltip, and
called the current arrangement a load-order race. Measured, it is not one. Bootstrap
5.0.2 defines its jQuery plugins on DOMContentLoaded, after every plain <script> in
the document, so it wins the name in both arrangements - jQuery UI before it, as
base.html used to, and after it, as result_cross.html now does. Checked on every page
that renders a [data-toggle="tooltip"] target: $.fn.tooltip.Constructor.NAME is
"tooltip", bootstrap.Tooltip.getInstance(el) is set, $(el).data("ui-tooltip") is not.
What does flip it is loading jQuery UI *after* DOMContentLoaded, which is exactly what
a lazy loader would do - so the hazard is lazy loading, not ordering.
test_bootstrap_is_loaded_synchronously pins that.

The one factual correction: the previous commit said DataTables' initialiser "selected
an element the app never renders". The app does render id="job-table" - job_table
still defaults to it and job_overview and single_sample take the default, confirmed on
/explore/samples/1. What made DataTables dead is narrower: the initialiser lived on
the jobs page, which passes table_id=active. The removal stands; the reason in the
comments and the test docstring did not, and now says what was measured.

New tests, each mutation-checked by breaking the code it guards:

  TestTheJobsPage             - none of the three jobs views renders id="job-table"
  TestTheCrossComparePage     - the rendered page ships jquery-ui, jquery.js reaches
                                it first, and no other page ships it at all
  test_only_base_html_loads_a_jquery      - both CFG templates' second jQuery stays
                                            commented out
  test_bootstrap_is_loaded_synchronously  - no defer/async on the bundle

code_of() now strips HTML comments as well as Jinja ones, which is what makes the
second-jQuery check see the commented-out includes as absent rather than present.
…zone, gzip

Font Awesome is reduced to the icons the templates use, Bootstrap ships
minified and deferred, the Dropzone script and stylesheet load on the first
drag or on opening the modal, and responses over 1 KiB of compressible types
leave gzipped (MCRITWEB_COMPRESS_RESPONSES turns it off behind a proxy that
compresses itself).
ADR-0015 had left compression to the proxy and the other bullets to a later
audit. Both happened; 0015 is marked superseded and 0016 holds the
measurements and the rules that follow from them.
The type-ahead conflicts are the ones that matter. This branch's side of
js/ac_family_names.html and the submit dropzone still carried the old
family-name code - names shipped with |tojson and pushed unescaped into a
widget that renders suggestions through innerHTML, which is the injection
master closed in #168 (and #146 moved to a JSON endpoint). Master's
escaped code is kept in both places; what this branch contributes there
is only its reason to change them, that Bootstrap is now deferred, so the
widgets are built once the deferred scripts have run. In
ac_family_names.html the DOMContentLoaded listener is also the scope,
replacing master's IIFE, so this branch's timing test can see it. The
Playwright tests that drive the real widget pass with Bootstrap deferred.

The rest:
- base.html: the minified Bootstrap and the Font Awesome subset, with
  master's signed-in font preload (#62) - the subset loads the same
  ../webfonts/fa-solid-900.woff2 the preload names; Bootstrap and
  post_action.js deferred, page_loading.js kept a plain script as master
  has it; clearDropzone keeps the lazy-load guard with master's const.
- the dropzone keeps mcritInitDropzone(), with master's const myDropzone
  (#61) - nothing outside that function uses it.
- import.html takes master's import status script, with dropzone.min.js.
- README keeps the compression paragraph and master's reverse-proxy
  section.
- the Font Awesome subset is regenerated for three icons master's
  templates added (arrows-rotate, code, diagram-project), nothing else
  changes in it; the subset script lists the webfont file stems as
  non-glyphs, since master's preload and its comment name
  fa-solid-900.woff2 and the icon scan read that as an icon.

1026 passed, ruff clean.
autocomplete.js and page_loading.js were plain scripts in <head>, so they
blocked first paint although nothing calls them while the page parses:
page_loading.js only registers event listeners, and every `new Autocomplete`
already waits for DOMContentLoaded, which fires after all deferred scripts
have run. Both are now deferred alongside Bootstrap and post_action.js.
jQuery stays a plain script because inline blocks call `$` while parsing.
The single function and function comparison pages loaded d3, graphlib,
graphlib-dot, dagre-d3 and convexhull.js as plain scripts in <head>, about
120 kB gzipped (390 kB raw) that held back the first paint although
nothing uses them before the CFG scripts at the end of the page and
window.onload. They now load immediately before main.js / main_duo.js, in
the same order, so every script that uses them still runs after them.
Lighthouse's desktop run of the comparison page no longer lists them as
render-blocking.
/help shows 21 screenshots, about 2 MB, and the browser fetched all of
them on load, so the first one - the page's largest contentful paint -
shared the connection with twenty images below the fold. Every screenshot
after the first now carries loading="lazy". The first stays eager:
lazy-loading the largest paint element would delay it.
With loading="lazy" and no width or height, a screenshot is a 2px placeholder
until it arrives. The browser scrolls to /help#jobs-queue, the screenshots now
in view load and grow, and the heading ends up 4,782px below the window (1400x900)
and stays there. Every section link past the first few screenshots missed.

manual.py reads each PNG's size from its header and writes it on the <img>.
With height: auto in style.css the space is reserved before the image loads,
and the image still scales down with the column. Every anchor now lands at the
top of the window, at 1400x900 and 800x700, and only the screenshots in view
download.
…libraries

Master replaced the family names shipped with each page by a type-ahead that
fetches them as they are typed (#192), and the submit dropzone now includes
js/ac_family_names.html instead of building its own list. Kept master's
widget and this branch's reason to touch it: Bootstrap is deferred, so the
widgets are built in a DOMContentLoaded listener rather than master's IIFE.
The dropzone macro takes master's signature without `families` and keeps
`lazy`, which base.html's overlay still passes.
The lazy loader, the query and submit pages and the import page loaded
static/dropzone.min.js, which is stock Dropzone 5.9.2. Only dropzone.js
carries the patch that sends the head of a dropped file, so a drop posted
no file_header and the submit form was no longer pre-filled. All three
load dropzone.js again; dropzone.min.js is the retired file now.

A failed fetch of the script left mcritDropzoneLoading set, so the overlay
never opened again on that page. It is cleared on error, and the next drag
tries again without adding a second stylesheet. A dragover while the
script is on its way no longer queues the same callback again. The two
URLs go into the script through |tojson.
send_file answers If-None-Match against the plain ETag before the
after_request hook renames it, so a client revalidating its gzipped copy
never matched and downloaded every asset again. The conditional check is
made again against the renamed ETag.

HTML is no longer compressed. A page carries the session's CSRF token, the
same in every response, next to input it reflects, which is what a BREACH
attack needs. Downloads, the /api passthrough, bodies of unknown length
and bodies over 1 MiB are left alone too: the exports and the cached
result download are streamed so that they never sit in memory whole, and
reading them in to gzip them undid that.

gzip;q=0 is a refusal; request.accept_encodings reads it as one. The
README said docker-mcrit's NGINX compresses; its configuration has no
gzip directive (ADR 0015).
…irect in its test

Master's templates now use fa-pen, which the Font Awesome subset did not carry, so
scripts/subset_fontawesome.py is rerun. /data/jobs now redirects to the URL that
names its first tab, so the DataTables id check follows the redirect to the page
that is actually rendered.
Batch C brought master docs/adr/0016-slow-function-search-is-mcrits.md,
so this branch's 0016 shared the number. The record moves to 0017 and
ADR-0015's status line points at it; nothing else names the file.
jQuery was the one script in every page's head that still held back the
first paint: inline blocks called $ while the page parsed, so 0017 left it
a plain script. base.html now defines whenReady(fn), which waits for
DOMContentLoaded and hands fn to jQuery, so ready handlers keep the timing
and order they had. The 21 parse-time uses of $ in 15 templates, and the
settings page's Sortable calls, run from it, and jQuery, jQuery UI and
SortableJS are deferred. Bootstrap loads below {% block style %}, so that it
still owns $.fn.tooltip over jQuery UI on the cross compare.

Between the first paint and DOMContentLoaded a click can now reach a page
whose jQuery has not run:
- the pickers' search forms are bound to document while the page parses,
  so an early Enter keeps the selection and the settings;
- fetchState reads its checkboxes and deleteSample finds its row without
  jQuery;
- the sample list's Analyze flag starts cleared;
- the upload radios leave their fields to the ready handler, which now
  also shows them for SMDA;
- the navbar's Analyze and Data menus link to "#" instead of reloading
  the page.

ADR-0018 records the audit, the rule for templates and what it costs.
testParseTimeScripts fails on a parse-time use of anything a deferred
script defines, and testDeferredJqueryBrowser drives the pages with
jquery.js held back.
With #304 jQuery, post_action.js, page_loading.js, the type-ahead, a
page's own jQuery plugins and Bootstrap are deferred, but a deferred
script is still fetched at once, alongside the stylesheets the page is
painted with. base.html now queues them with later() and loads the queue,
in order, once the browser reports the first contentful paint, with a
fallback for browsers without paint timing, at once for a page that is
not visible, and a backstop three seconds after DOMContentLoaded.
whenReady runs its functions once the queue has run, and at once after
that. A click on a Bootstrap control or a data-post button before then is
held and made again; a tooltip toggle is not, since a tooltip acts on
hover and focus. csrfToken() moves into base.html's first script,
since the CFG viewers call it from window.onload. The upload form's ready
handler sets its fields instead of sliding them, and the copy buttons
copy before the queue is in and confirm once it is. ADR-0021 records it.
test_the_queue_is_fetched_once_the_page_has_been_painted sorted the
scripts' resource entries by startTime and compared that with the queue.
The browser does not have to start the requests in the order the scripts
were added: on a branch that queues two more scripts it started one ahead
of another queued before it, in one run of six under load, and the test
failed. What the queue does promise is the order the scripts run in
(async = false), and the old assertion did not hold that: with async set
to true it still passed in two runs of three.

The test now records each script's load event, which fires once the
script has run, and compares that order with the queue. The requests are
still checked to be the queued scripts and to start after the first
paint.
@danielplohmann

Copy link
Copy Markdown
Collaborator

Once the CFG batch's lazy viewer loaders (#310/#312) are in, main.js, main_duo.js and d3 are no longer plain
<script> tags. tests/testParseTimeScripts.py::test_the_plain_scripts_are_the_expected_ones then fails, and more
importantly the "$ before the queue" check stops scanning those files. It's latent today (the only $ uses are in
setupHighlight()/countlines(), and setupHighlight()'s only call is commented out), but please make
plain_scripts() also read the URLs in the viewer lists of single_function.html and
result_compare_function_vs.html, so the guard keeps covering them.

Once #310 and #312 load the graph viewer from a list of URLs instead of
plain <script> tags, plain_scripts() no longer saw main.js, main_duo.js
or d3, and the check that a plain script does not need jQuery stopped
covering them. Read the viewer lists as well.
@r0ny123

r0ny123 commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

Done: plain_scripts() now also reads the URLs in the var viewer = [...] lists that #310 and #312 load lazily, so the "$ before the queue" check keeps scanning main.js, main_duo.js and d3 once those land. A new test checks a snippet written the way #310 and #312 write it. On a scratch tree with #310's and #312's templates, the new code still finds all three files, and the old code finds none.

held_back() unrouted jquery.js in release(). Called just as the queue started, it
drained nothing, and the request the browser had caught by then was never handed on,
so jQuery never loaded and release() timed out: one run in three or four of
test_a_search_keeps_the_pickers_state. The route now stays, and passes everything
through once released.
# Conflicts:
#	mcritweb/__init__.py
#	mcritweb/templates/base.html
#	mcritweb/templates/single_sample.html
#	mcritweb/templates/table/family_row.html
#	mcritweb/templates/table/function_row.html
#	mcritweb/templates/table/links.html
#	mcritweb/templates/table/sample_row.html
#	mcritweb/templates/table/submit_or_query_dropzone.html
Master's #293 loads live_search.js with a plain script tag on the four
listing pages, so it was fetched before the first paint, which this
branch moves every page script past (ADR-0021). It is queued with later()
now. The search box has autofocus, so a term can be typed before the
queue has run: the script takes the term the page was rendered for as the
one on screen and searches what the box holds by the time it runs.
Master's legacy-token notice and statistics page use fa-key and
fa-triangle-exclamation, which the cut stylesheet did not name.
Regenerated with scripts/subset_fontawesome.py; the fonts are unchanged.
Each screenshot carries the pixel size of its file as width and height, but the
page is box-sizing: border-box and a screenshot has a 1px border, so the
picture inside was 2px narrower than its file (1265px for a 1267px file) and
was resampled. The border now goes around the size, and the largest width the
column allows loses the 2px, so a screenshot that does not fit still shrinks to
the column. The room kept for it before it loads is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants