Skip to content

Minify API pages and print each property path once - #4945

Closed
akira28 wants to merge 3 commits into
mainfrom
feature/api-explorer-webmarkupmin
Closed

akira28 wants to merge 3 commits into
mainfrom
feature/api-explorer-webmarkupmin

Conversation

@akira28

@akira28 akira28 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

API Explorer pages now pass through WebMarkupMin before they are written, and each property row prints its JSON path once. API HTML is 11% smaller, and 25 of the 71 pages over Googlebot's 2 MB limit get under it. This replaces #4944: it takes over #4944's leaner rows, and the minifier replaces #4944's whitespace step.

Affects: API reference, Site UI

Prompt summary: Try an off-the-shelf .NET HTML minifier, WebMarkupMin, on the API pages in a separate PR from main, and see what it does to page size and output. Then bring the leaner property rows over from #4944, so one PR has both. The goal behind it is elastic/docs-eng-team#1183: bring API pages under Googlebot's 2 MB HTML limit.

Why

Googlebot reads only the first 2 MB of an HTML page. With today's specs, 71 API operation pages are over that limit. Most of their bytes are markup: indentation a browser ignores, and a row partial that repeats thousands of times. Each row prints its JSON path twice and carries an icon span.

What

Every API page is minified before it is written

OpenApiGenerator renders each page into memory, and ApiHtmlMinifier minifies it with WebMarkupMin 2.24.0 before writing the file. The minifier removes whitespace between elements, comments, and redundant attributes, and it trims embedded CSS and JS. It keeps attribute quotes and optional end tags. Removing those would save about 3% more, but it makes the markup differ from what the views write and breaks 18 tests that match it. If the minifier reports an error, the page is written as rendered and a warning is logged.

hidden="until-found" survives

WebMarkupMin treats hidden as a plain boolean, so it rewrites hidden="until-found" to hidden or hidden=hidden. Find in page then stops opening folded rows, and the CSS fallback for [hidden='until-found'] stops matching. ApiHtmlMinifier swaps that value for a stand-in attribute before minifying and restores it afterwards. A unit test fails without the swap. The bug is reported upstream as Taritsyn/WebMarkupMin#185, and the swap goes once a fixed version ships.

A property row prints its path once

The permalink keeps the full path in its aria-label, so screen readers still announce query.bool.must[].match. The name's mono tooltip now reads the path from that label (tooltip.ts) and no longer carries its own data-tippy-content and data-tippy-theme. A top-level field still shows no tooltip. A minifier can't remove this duplicate, because both copies are real attribute values.

The link icon is the anchor

CSS now draws the copy-link icon as the anchor's ::after, which replaces the span.property-anchor-icon in every row. The "Copy link" tooltip, the copy-on-click and the hover and focus states move to the a.property-anchor itself.

Results

From an isolated build of docs/ with the AOT binary, compared with main:

main Minifier only This PR
Pages over 2 MB 71 62 46
Total API HTML 2.56 GB 2.35 GB 2.27 GB (−11%)
indices-create 2,417 KB 2,269 KB 2,014 KB
simulate-ingest 3,239 KB 3,060 KB 2,664 KB
Kibana get-dashboard 7,415 KB 7,095 KB 6,449 KB
  • Minifying makes the docs build about a minute slower for 7,243 API pages. Two runs measured 57 s on main against 112 s with the minifier; a later run on a slower network measured 87 s against 155 s. I have not profiled where that time goes.
  • A DOM comparison of 153 pages (every start tag, its attributes, and the text with whitespace normalized) found the minifier changes nothing except a Kibana spec update between the two builds. That check ran before the row changes, which change the markup on purpose.
  • The AOT publish reports no trim or AOT warnings from WebMarkupMin, and the minifier reported no errors on any page.

Out of scope: the 46 pages still over 2 MB: the Elasticsearch template and simulate-ingest pages, and the Kibana dashboard and visualization pages. They need the content changes listed on elastic/docs-eng-team#1183. The api-explorer browser journey needs an assembler build, so it was not run.

Verify

dotnet test --project tests/Elastic.ApiExplorer.Tests
# ApiHtmlMinifierTests: hidden="until-found" kept, inline spaces kept, pre content kept
# JsonPathTests.Render_Row_PrintsPathOnce
mise run site:test
# tooltip.test.ts: property name tooltips; api-property-anchor-copy.test.ts

Build the docs and count the pages over 2 MB:

dotnet run --project src/tooling/docs-builder -c Release -- --path docs --output .artifacts/iso
find .artifacts/iso/api -name index.html -size +2048k | wc -l   # 46, was 71 on main

Check on the preview

  • Elasticsearch: Create an index — hover a nested name such as settings.analysis.analyzer for its path tooltip. Hover the row for the link icon and click it to copy the link. Use find in page on a folded field such as kuromoji_iteration_mark; its row should open.
  • Elasticsearch: Search — code samples and example JSON keep their line breaks and indentation; type annotations keep the spaces around or.
  • Kibana: Get a dashboard — expand and collapse a few levels; toggles and tooltips work.
  • Elasticsearch: Cluster health — control: a top-level field shows no path tooltip, and the page looks the same as on main.

🤖 Generated with Claude Code

Some API operation pages pass Googlebot's 2 MB HTML limit. Each API page
is now rendered in memory and minified with WebMarkupMin 2.24.0 before it
is written. The minifier keeps attribute quotes and optional end tags,
which cost about 3%, so the markup stays as the views write it.

WebMarkupMin treats `hidden` as a plain boolean and rewrites
`hidden="until-found"` to `hidden`, which stops find in page from opening
folded rows. `ApiHtmlMinifier` swaps that value for a stand-in attribute
and back. A page the minifier reports errors on is written as rendered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Docs preview (local build)

Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4945/

The minifier cannot remove markup a row repeats on purpose. Each row
printed its JSON path twice, in the permalink's `aria-label` and in the
name's tooltip, and carried an icon `span`. The tooltip now reads the path
from the `aria-label` in `tooltip.ts`, and CSS draws the icon on the
anchor. With the minifier, 46 of 71 pages stay over 2 MB, down from 62.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@akira28 akira28 changed the title Minify API pages with WebMarkupMin before writing them Minify API pages and print each property path once Nov 19, 2026
@akira28
akira28 marked this pull request as ready for review November 19, 2026 09:59
@akira28
akira28 requested a review from a team as a code owner November 19, 2026 09:59
@akira28
akira28 requested a review from theletterf November 19, 2026 09:59
<code>@Model.Name</code>
}
@* The icon is drawn by CSS, and the name's path tooltip reads the path from this label, so a row prints it once. *@
<a class="property-anchor" href="#@Model.AnchorId" aria-label="Link to @Model.PermalinkLabel" data-tippy-content="Copy link"></a>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P2 (Medium)

With NAVIGATION_PREVIEW on, removing span.property-anchor-icon here also removes the copy-link icon. Flag-on pages load only ds.css, and its Components/Pages/ApiReference/api-reference.css still draws the icon on .property-anchor-icon / .property-anchor-icon::after (around lines 1484–1530). Without that span, the anchor is empty and nothing styles it, so every property row on design-system API pages loses its visible permalink/copy control. Please port the ::after icon and hover/focus rules to a.property-anchor in api-reference.css too.

Generated by Libra. Specialist: libra-complexity. React with 👍 or 👎 to give feedback on this comment.

generateStatistics: false
);
if (result.Errors.Count == 0)
return result.MinifiedContent.Replace(UntilFoundStandIn, UntilFound, StringComparison.Ordinal);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P3 (Low)

The global replacement also rewrites literal data-api-hidden-until-found text in code samples, even when the original page has no hidden="until-found" attributes. That changes what readers see and copy. Restore only attributes that this pass actually substituted.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

Comment on lines +15 to +20
var buffer = new MemoryStream();
var position = Position;
Position = 0;
CopyTo(buffer);
Position = position;
return buffer.ToArray();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P3 (Low)

Reading each page copies the full output into a second MemoryStream and then copies it again with ToArray(), just to decode it. These extra page-sized allocations add GC pressure when multi-megabyte pages render in parallel. Decode the written region of the original MemoryStream buffer instead.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

const href = icon
?.closest<HTMLAnchorElement>('a.property-anchor')
?.getAttribute('href')
const icon = e.target.closest<HTMLAnchorElement>('a.property-anchor')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P3 (Low)

Response-header links still put their tooltip on a child span, but the copy handler now flashes the anchor. Clicking a response-header link copies the URL without updating its tooltip to “Copied!”. Migrate the response-header markup too, or flash the child when one is present.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@reakaleek

Copy link
Copy Markdown
Member

Do you also have build time measurements?

@akira28

akira28 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Do you also have build time measurements?

yes, they are in the description, I'm investigating why it takes that much, and further improvements

@akira28

akira28 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Closing: the stack #4952 → #4953 → #4955 → #4956 → #4959 replaces this. Its row changes are in #4956. #4959 uses a plain whitespace collapse instead of WebMarkupMin. That gets 46 pages over 2 MB against 41 here, without the extra ~55 s per build, the dependency, and the hidden="until-found" workaround (Taritsyn/WebMarkupMin#185).

@akira28 akira28 closed this Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants