From 00dd69544e977a5cb18f4039191597bc81430bd6 Mon Sep 17 00:00:00 2001 From: Derek Lewis Date: Tue, 25 Aug 2026 22:05:26 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=F0=9F=9A=80=EF=BC=9Aminif?= =?UTF-8?q?y=20the=20HTML=20that=20gets=20served?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every page ships with the indentation the templates are written in. Across the twenty pages that is 70KB of whitespace and comments, a fifth of the HTML, and 3.6KB once gzipped -- which is the figure that counts, since what serves the site compresses it. Only the build that publishes, so `_site` stays readable in a diff and in the browser while developing. The stylesheet already splits that way, between `main.css` and `main.min.css`. Two settings are load-bearing rather than incidental. Attribute names stay case-sensitive: SVG carries `viewBox` and `preserveAspectRatio`, and a lowercased attribute is one the browser does not act on. Attributes and class names are sorted, which saves nothing by itself and gives the compressor longer runs to find. Signed-off-by: Derek Lewis Assisted-by: Claude-Code:claude-opus-5 Refs: https://github.com/OpenINF/openinf.github.io/issues/1543 --- eleventy.config.mjs | 33 ++++++++++ package.json | 1 + pnpm-lock.yaml | 145 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+) diff --git a/eleventy.config.mjs b/eleventy.config.mjs index 55cd6ad29..78bbd0415 100644 --- a/eleventy.config.mjs +++ b/eleventy.config.mjs @@ -4,6 +4,7 @@ import { EleventyI18nPlugin } from '@11ty/eleventy'; import { PATHS } from '@openinf/portal/build/constants'; import autoprefixer from 'autoprefixer'; import cssnano from 'cssnano'; +import { minify as minifyHtml } from 'html-minifier-terser'; import markdownItAnchor from 'markdown-it-anchor'; import markdownItFootnote from 'markdown-it-footnote'; import markdownItGitHubAlerts from 'markdown-it-github-alerts'; @@ -170,6 +171,38 @@ export default async function (eleventyConfig) { }, }); + // Only the build that publishes. A reader downloads this output; a + // developer reads `_site` in a diff. + if (isProduction) { + eleventyConfig.addTransform('minifyHtml', function (content) { + // Sass partials output nothing, and their `outputPath` is `false` + // rather than absent, which optional chaining does not catch. + const output = this.page.outputPath; + + if (typeof output !== 'string' || !output.endsWith('.html')) { + return content; + } + + return minifyHtml(content, { + // `
` and `