feat(rendering): minify rendered HTML behind FEATURE_FLAG_MINIFY_HTML - #36852
Open
fmontes wants to merge 1 commit into
Open
feat(rendering): minify rendered HTML behind FEATURE_FLAG_MINIFY_HTML#36852fmontes wants to merge 1 commit into
fmontes wants to merge 1 commit into
Conversation
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
feat(rendering): minify rendered HTML behind FEATURE_FLAG_MINIFY_HTMLcb242c7Uh oh!
There was an error while loading. Please reload this page.
Claude finished @fmontes's task in 1m 58s —— View job
Code Review — native HTML minification
HtmlMinifier.javaVelocityLiveMode,VelocityModeHandler)FeatureFlagName+ testsNice work — the design (two seams, cache-fill-time minification, best-effort fallback, idempotency, preserved regions) is sound and well-documented. One real correctness bug stands out.
New Issues
🟠 High:
dotCMS/src/main/java/com/dotcms/rendering/util/HtmlMinifier.java:80-142— Whitespace inside quoted attribute values is collapsed.minify()tracks no tag/attribute context;isSignificantBefore/isSignificantAfteronly look at the immediately adjacent characters. Any whitespace run whose neighbors are not>/<is treated as significant inter-element text and collapsed to a single space — including whitespace inside an attribute value.Trace
<input value="a b">: thea brun is preceded bya(≠>, significant) and followed byb(≠<, significant) → emitted asa b. Output becomes<input value="a b">.Impact when the flag is on:
<input type="hidden" value="two spaces">→ submitted form value silently changes.data-config='{"key": "a b"}'and other JSON/data payloads → value changes, can break client JS.alt/title/aria-labelwith intentional spacing → altered.This is silent data corruption, not just cosmetic. The existing test
test_minify_collapses_attribute_and_document_whitespaceonly covers whitespace between attributes (<div class="a" id="b">), so the case is untested. A minimal fix is to track whether the cursor is inside a tag and inside a quoted value, and copy attribute-value whitespace verbatim (and add a regression test).Fix this →
Notes (non-blocking)
HtmlMinifier.java:253-266— thewhileloop infindPreserveTagEndalways returns on its first iteration (the trailingreturn html.length()after the loop is unreachable). Not a bug, but the loop reads as if it iterates over multiple close-tag candidates when it does not. Consider replacing with a straight-line lookup for clarity.VelocityModeHandler.eval():111-113— CSP-then-minify ordering is correct, and applying the minifier to preview/edit output is harmless. Good.VelocityLiveMode.writePage:265-280) correctly minifies before the cacheadd(), so the cost is paid per cache fill, and the non-minify branch still streams directly. Good.Everything else — feature-flag gating,
Config.getBooleanProperty,Logger.warnAndDebugon failure returning original markup, preserved-region handling, conditional-comment retention — follows dotCMS conventions and looks correct.• branch
issue-36851-native-html-minificationThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds a feature-flagged, dependency-free HTML minification step to dotCMS’s rendering pipeline so rendered pages can be served (and, in LIVE mode, cached) without indentation/blank lines/comments introduced by Velocity templates—opt-in via
FEATURE_FLAG_MINIFY_HTML.Changes:
HtmlMinifierto conservatively collapse insignificant whitespace and strip HTML comments while preserving<pre>,<textarea>,<script>, and<style>bodies.VelocityLiveMode.writePage()(before page cache write) and intoVelocityModeHandler.eval()(post-CSP processing path).FEATURE_FLAG_MINIFY_HTMLand a new unit test suite for the minifier.Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
FEATURE_FLAG_MINIFY_HTML.eval()output (after CSP application when configured).FEATURE_FLAG_MINIFY_HTMLfeature flag constant + javadoc.