kenshodigital / kirby-minify
Minifies HTML and XML output for Kirby projects.
Package info
github.com/kenshodigital/kirby-minify
Type:kirby-plugin
pkg:composer/kenshodigital/kirby-minify
Requires
- php: ^8.5
- ext-dom: *
- getkirby/cms: ^5.2
- getkirby/composer-installer: ^1.2
Replaces
README
Minifies HTML and XML output for Kirby projects.
General
The plugin extends Kirby’s core template component and directly applies post-processing to template-based HTML and XML output. It removes comments and trims trailing whitespace from text nodes, using PHP’s native DOM parsers.
Further reading
Usage
Installation
composer require kenshodigital/kirby-minify ^1.0
Setup
The plugin works out-of-the-box, no further configuration required.
FAQ
Why extend the template component instead of using hooks?
Pages somehow always require a default HTML template and are therefore not well suited for other content types, such as XML sitemaps or other XML-only responses. Thus, the pages.render:after hook can’t be used to apply minification in such cases where you want to simply render a template directly instead.
The route:after hook, on the other hand, doesn’t always pass information about the content type of the rendered response, so it’s also not a good fit here.