metacpan-web
metacpan-web copied to clipboard
[RFE] Minify/Compact HTML to reduce bandwidth usage
The HTML produced by MetaCPAN is indented, which adds to the bandwidth usage of the site.
You may want to consider using something like Plack::Middleware::Text::Minify which removes HTML indentation on-the-fly.
(Note: I'm the author of that module.)
I don't think this would be very worthwhile. Testing on a random page shows a difference of less than 3% savings in size, and it makes development harder.
Piping the text from various URLs
use v5.34;
use Text::Minify::XS qw/ minify /;
my $body = join("", <STDIN>);
say length($body);
say length(minify($body));
using something like
curl -s https://metacpan.org/ | perl minify.pl
Gives me:
$ curl -s https://metacpan.org/ | perl minify.pl
13980
9962
$ curl -s https://metacpan.org/recent | perl minify.pl
123374
105428
$ curl -s https://metacpan.org/release/RRWO/Text-Minify-XS-v0.6.2 | perl minify.pl
36655
30513
$ curl -s https://metacpan.org/pod/Plack | perl minify.pl
120953
106923
That's significantly more than 3%.
Under normal use, the pages will be compressed with gzip.
Under normal use, the pages will be compressed with gzip.
The point is the uncompressed pages are larger, and this will still affect storage in cache (and possibly memory usage). Even if browsers are stream-parsing, that's 20% less data to parse.
More to the point, this doesn't require much work beyond adding a couple of lines to the .psgi
file that enable it and perhaps limit it to text/
MIME-types.
I use it on some sites that I maintain. I've not found it being difficult to work with as a developer, since the HTML still has newlines. (Developers may be more likely to use Browser-based developer tools to inspect the DOM than to look at HTML source.) It's easy enough to write conditional middleware to disable on development environments as well.
Note: Edited