Plack::Middleware::Text::Minify - remove HTML indentation on the fly
version v0.3.0
use Plack::Builder; builder { enable "Text::Minify", path => qr{\.(html|css|js)}, type => qr{^text/}; ... };
This middleware uses Text::Minify::XS to remove indentation and trailing whitespace from text content.
It will be disabled if the psgix.no-minify environment key is set to a true value. (Added in v0.2.0.)
psgix.no-minify
This is a regex or callback that matches against PATH_INFO. If it does not match, then the response won't be minified.
PATH_INFO
The callback takes the PATH_INFO and Plack environment as arguments.
By default, it will match against any path except for HTTP status codes with no bodies, or request methods other than GET or POST.
GET
POST
This is a regex or callback that matches against the content-type. If it does not match, then the response won't be minified.
The callback takes the content-type header and the Plack reponse as arguments.
By default, it will match against any "text/" MIME type.
This module requires Perl v5.9.3 or newer, which is the minimum version supported by Text::Minify::XS.
If you are using a templating system with directives that collapse whitespace in HTML documents, e.g. in Template-Toolkit
[%- IF something -%] <div class="foo"> ... </div> [%- END -%]
then you may find it worth removing these and letting the middleware clean up extra whitespace.
The underlying minifier does not understand markup, so newlines will still be collapsed in HTML elements where whitespace is meaningful, e.g. pre or textarea.
pre
textarea
Text::Minify::XS
PSGI
The development version is on github at https://github.com/robrwo/Plack-Middleware-Text-Minify and may be cloned from git://github.com/robrwo/Plack-Middleware-Text-Minify.git
Please report any bugs or feature requests on the bugtracker website https://github.com/robrwo/Plack-Middleware-Text-Minify/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Robert Rothenberg <rrwo@cpan.org>
This software is Copyright (c) 2020-2021 by Robert Rothenberg.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Plack::Middleware::Text::Minify, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::Text::Minify
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::Text::Minify
For more information on module installation, please visit the detailed CPAN module installation guide.