Plack::Middleware::Precompressed - serve pre-gzipped content to compression-enabled clients
version 1.004
use Plack::Builder; builder { enable 'Plack::Middleware::Precompressed', match => qr!\.js\z!; $handler; };
Plack::Middleware::Precompressed is an alternative (or rather, complement) to middlewares like Deflater, which will compress response bodies on the fly. For dynamic resources, that behaviour is necessary, but for static resources it is a waste: identical entities will be compressed over and over. Instead, Precompressed allows you to compress static resources once, e.g. as part of your build process, and then serve the compressed resource in place of the uncompressed one for compression-enabled clients.
To do so, it appends a .gz suffix to the request URI and tries to serve that. If that fails, it will try again with the unmodified URI.
.gz
Note: this means requests for resources that are not pre-compressed will always be dispatched twice. You are are advised to use either the match parameter or the Conditional middleware or something of the sort, to prevent requests from passing through this middleware unnecessarily.
match
Specifies a regex that must match the request URI to trigger the middleware.
Plack::Middleware::Deflater
Aristotle Pagaltzis <pagaltzis@gmx.de>
This software is copyright (c) 2011 by Aristotle Pagaltzis.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Plack::Middleware::Precompressed, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::Precompressed
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::Precompressed
For more information on module installation, please visit the detailed CPAN module installation guide.