From 220607a501d8c1d3c47ea51e5ef5d8d1bd74a29a Mon Sep 17 00:00:00 2001 From: Wolfgang Klinger Date: Mon, 22 Jun 2026 08:12:00 +0200 Subject: [PATCH] Add option to disable minification entirely --- Classes/Service/MinifyService.php | 4 ++++ README.md | 17 +++++++++++++++++ Tests/Unit/Service/MinifyServiceTest.php | 20 ++++++++++++++++++++ ext_conf_template.txt | 3 +++ 4 files changed, 44 insertions(+) diff --git a/Classes/Service/MinifyService.php b/Classes/Service/MinifyService.php index 84850b3..612c557 100644 --- a/Classes/Service/MinifyService.php +++ b/Classes/Service/MinifyService.php @@ -12,6 +12,10 @@ class MinifyService { public function minify(string $html): string { + if ($this->isFeatureActive('disabled')) { + return $html; + } + $htmlMin = new HtmlMin(); $htmlMin->doOptimizeViaHtmlDomParser($this->isFeatureActive('optimize_via_html_dom_parser')); $htmlMin->doSumUpWhitespace($this->isFeatureActive('sum_up_whitespace')); diff --git a/README.md b/README.md index ee317fd..92bc720 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,23 @@ These can be configured by extension configuration. `composer req pluswerk/minify` +# Disabling minification + +Set the `disabled` extension configuration option to `1` to switch minification +off completely. The default is `0` (minification active). + +This is handy for environment-specific behaviour. To keep the HTML readable in +development while leaving it active everywhere else, set it per context in +`config/system/additional.php`: + +```php +use TYPO3\CMS\Core\Core\Environment; + +if (Environment::getContext()->isDevelopment()) { + $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify']['disabled'] = '1'; +} +``` + # Benefits - Less Data to transfer - Nice looking code diff --git a/Tests/Unit/Service/MinifyServiceTest.php b/Tests/Unit/Service/MinifyServiceTest.php index dc74aff..d2ab333 100644 --- a/Tests/Unit/Service/MinifyServiceTest.php +++ b/Tests/Unit/Service/MinifyServiceTest.php @@ -110,6 +110,26 @@ public function minifyRemovesRegularCommentButKeepsTypo3CommentWhenBothFlagsAreE self::assertStringNotContainsString('', $result); } + // ------------------------------------------------------------------------- + // Master switch — disabled + // ------------------------------------------------------------------------- + + #[Test] + public function minifyReturnsHtmlUntouchedWhenDisabled(): void + { + $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify']['disabled'] = '1'; + // Features that would otherwise transform the output are on, to prove + // the disabled switch short-circuits before any minification happens. + $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify']['optimize_via_html_dom_parser'] = '1'; + $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['minify']['remove_comments'] = '1'; + + $html = '

Hello

'; + + $result = $this->subject->minify($html); + + self::assertSame($html, $result); + } + // ------------------------------------------------------------------------- // Output integrity // ------------------------------------------------------------------------- diff --git a/ext_conf_template.txt b/ext_conf_template.txt index 5f01b04..6f43cf8 100644 --- a/ext_conf_template.txt +++ b/ext_conf_template.txt @@ -1,3 +1,6 @@ +# cat=plus_minify; type=boolean; label=disable minification entirely (e.g. set to 1 in Development via AdditionalConfiguration.php) +disabled = 0 + # cat=plus_minify; type=boolean; label=optimize html via "HtmlDomParser()" optimize_via_html_dom_parser = 1