This is a standalone example for static Astro projects. The site where I measured it, straffesites.com , does not use the script in production. In October 2026, I did run it on a copy of that site's build to measure what a post-build step does to your Astro HTML. The script adds unique IDs to headings that do not have one yet and minifies the files with html-minifier-terser. Here is how to set it up, what the measurement showed, and what to watch out for.
What do you need to get started?
Before you start, make sure you have the following installed:
Node.js (version 22.12.0 or later for Astro 7)
Astro (version 5 or later)
Installing the dependencies
The script depends on three packages: globby , html-minifier-terser , and jsdom . Install them as development dependencies:
npm install --save-dev globby html-minifier-terser jsdom
Enter fullscreen mode
Exit fullscreen mode
The process-html.mjs script
Create a file named process-html.mjs in the root of your Astro project.…