[Catalyst] Compress HTML

Bill Moseley moseley at hank.org
Sun Sep 11 04:27:49 GMT 2011

On Fri, Sep 9, 2011 at 1:14 AM, Stefan <catalyst at s.profanter.me> wrote:

> > Guess you should pass a ref to $rendered to minify(), not the string
> itself.
> Yes!!! Thanks a lot! This did it. Here is the complete code for others:
Are you defalting/gzipping your content, too?

We don't have HTML comments in the markup, and our css and js is minified
and served statically (from a CDN).  Our load balancer does hardware
compression.  I've often wondered if the compressed size of the response
would be much different if we "packed" our markup first, and if the time to
"pack" each response would offset any gains in response size -- and more
specifically, client rendering time.

For us, it's mostly whitespace that would get packed, and that tends to get
compressed well.

Of course, this is really hard to measure w/o knowing your client's
connection in detail.  If concerned about your site it's best to attack
well-known areas of performance first.  This is a good reference:


Might also run your site through:



> use HTML::Packer;
> use JavaScript::Packer;
> use CSS::Packer;****
> my $html_packer =3D HTML::Packer->init();
> sub process {
>             my ( $self, $c ) =3D @_;
>             my $rendered =3D $self->render($c, $c->stash->{template});
>             my $opts =3D {
>                         remove_comments =3D> 1,
>                         remove_newlines =3D> 1,
>                         html5 =3D> 1,
>                         do_javascript =3D> 'best',
>                         do_stylesheet =3D> 'minify',
>             };
>             $html_packer->minify( \$rendered, $opts );
>             $c->response->body($rendered);
> }****
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/

-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110911/63dc1=

More information about the Catalyst mailing list