byte-saving techniques (was: [plug] Hacker challenge ends in feuding)
Ryan
ryan at is.as.geeky.as
Thu Jul 10 11:36:33 WST 2003
On Thu, 2003-07-10 at 10:42, Derek Fountain wrote:
<snip>
> > my code still runs rings around the opposition because bytes
> > still matter.
>
> Can you elaborate on that a bit?
>
> I started learning PHP a few weeks back in order to write a web based database
> app. Browser front end, MySQL and XML at the back, and PHP/Apache in the
> middle. (Is that the sort of thing you're refering to?) I found the
> technology very straightforward since PHP is a great language - simple, tuned
> to what it does, and highly effective.
<snip>
> So I'm interested in all aspects of this. In particular, what byte-saving
> techniques do you employ which make a difference to web based apps?
Firstly, good programming practices and myself are living in different
worlds, I just do what I can with what I know.
I get along with Perl better than PHP, but this concept is
transportable. There is a Perl module HTML::Clean which I use on the
output stages of all my CGI::Application modules. It strips needless
whitspace, trims tags etc.
While I'm developing I leave it off so I can check table structures and
whatever else I did wrong, then I turn it on. It makes the source a
mess to read at the client end, but it has meant a 40% saving on
bandwidth with the latest web app I spat out - which has about 260KB of
very bland HTML templates at its (looks at JamesD) disposal.
I also religiously use HTML::Template, there is not a single byte of
HTML in any of my Perl source, another reason I find it hard to switch
to PHP ... though I'm sure there are some reasonable templating
solutions for it too. While that would let me edit the HTML in some
fancy WYSIWYG thing, I use VIM for even the most complex of HTML - that
in itself is a fair amount of byte-saving :) Studious use of CSS can
also mean byte-savings if you don't already use it correctly.
Simply for reference:
sub clean {
use HTML::Clean;
my $cleaner = new HTML::Clean(\shift,9);
#$cleaner->compat();
my %options = (
whitespace => 1, # Remove excess whitespace
shortertags => 1, # <strong> -> <b>, etc..
blink => 1, # No blink tags.
contenttype => 1, # Remove default contenttype.
comments => 1, # Remove excess comments.
entities => 1, # " -> ", etc.
dequote => 1, # remove quotes from tag parameters where
possible.
defcolor => 1, # recode colors in shorter form. (#ffffff
-> white, etc.)
javascript => 1, # remove excess spaces and newlines in
javascript code.
htmldefaults => 1, # remove default values for some html tags
lowercasetags => 1, # translate all HTML tags to lowercase);
);
$cleaner->strip(\%options);
#$cleaner->defrontpage();
return $cleaner->data();
} # clean
Ryan
More information about the plug
mailing list