Skip to content

Commit ed77f70

Browse files
author
Miriad
committed
fix: aggressive HTML minification — collapse all whitespace including inside style attrs
The previous regex only stripped whitespace between tags. HTMLRewriter may also treat newlines inside style attributes as significant. New minifier: (1) strip between tags, (2) collapse all remaining whitespace to single spaces. Produces single-line HTML with no newlines anywhere. Build: 18.03s
1 parent aaa3776 commit ed77f70

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

apps/web/src/lib/og-utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ export function loadFonts() {
7070
// elements as text nodes. Template literal formatting creates phantom
7171
// text nodes that violate Satori's strict "display: flex" requirement.
7272
function minifyHtml(html: string): string {
73-
return html.replace(/>\s+</g, "><").trim();
73+
return html
74+
.replace(/>\s+</g, "><") // Remove whitespace between tags
75+
.replace(/\s+/g, " ") // Collapse all remaining whitespace (including inside style attrs)
76+
.trim();
7477
}
7578

7679
// ── Adaptive title font size ─────────────────────────────────────────

0 commit comments

Comments
 (0)