Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

HTML::Clean Review

by sheridan3003 (Beadle)
on Oct 15, 2001 at 21:37 UTC ( #118947=modulereview: print w/ replies, xml ) Need Help??

Item Description: Cleans up static HTML pages

Review Synopsis:

I work with a web site where the front-end developers use FrontPage to develop the UI. I began wondering if there was a way I could improve/shrink down the HTML they were generating.

I found HTML::Clean and began testing it.

This is a very easy way to shrink the static HTML done on a web site.

I used a small test site one of the developers had put together to test with.

I was able to achieve a 10% shrinkage of the total size of the directory. In the scheme of things this is not a big savings, however, as I begin to move on to the larger web sites we have built I believe a 10% savings will begin to show improved download times for our customers.

Thanks to some of the other PM members I have put together this small script to demonstrate the abilities of HTML::Clean. While I have tested this on my own directories you may want to ensure that you have backups of your html files prior to running this script on your directories since this will over write the files in the running directory.

#!/usr/bin/perl -w use strict; use HTML::Clean; clean_file( $_ ) foreach glob "*.html"; sub clean_file { my ($filename) = shift; print "$filename is being cleaned!\n"; my $h = new HTML::Clean($filename,9) or die "Couldn't load $filena +me: $!\n"; $h->compat(); $h->strip(); my $myref = $h->data(); open(OUTPUT,">$filename") or die "Can't open $filename: $!"; print OUTPUT $$myref; close(OUTPUT); }

Edit kudra, 2002-02-26 Added paragraph breaks; added 'review' to title per ntc req

Comment on HTML::Clean Review
Download Code
Re: HTML::Clean
by merlyn (Sage) on Oct 15, 2001 at 22:07 UTC
    You might consider an inplace edit instead:
    #!/usr/bin/perl $^I = ".bak"; $/ = undef; while (<>) { print STDOUT "$ARGV is being cleaned!\n"; my $h = HTML::Clean->new($_, 9); $h->compat; $h->strip; print ${$h->data}; }
    Now you get backups with ".bak" automatically. Good if something messes up.

    -- Randal L. Schwartz, Perl hacker

Re: HTML::Clean
by Hero Zzyzzx (Curate) on Oct 15, 2001 at 23:04 UTC

    HTML::Clean isn't only good for static HTML pages. I use it in a mod_perl content management system to shrink my page sizes and it works beautifully.

    I use this in combination with CGI::Application and HTML::Template. This is a wicked space saver for HTML::Template pages especially, because all the context variables in a template file leave behind whitespace after parsing (which makes sense at some level, especially if you're generating stuff in PRE tags.)

    I've found a shrinkage of 10-20% at a speed penalty of about 2-3% in combination with mod_perl. Pretty good savings! I use it at it's lowest level too.

    If the max performance of an application isn't bound by processor speed, I highly recommend using HTML::Clean!

    -Any sufficiently advanced technology is
    indistinguishable from doubletalk.

Back to Reviews

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: modulereview [id://118947]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2014-10-02 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (45 votes), past polls