2003-08-29 11:51:33

Google ads have now reached a bizarre peak — I get ads for cactus seeds, despite the lack of reference to either cactus or seeds in any of the articles I’ve put out so far (what’s up with that??). Sorry to say, but at this point I pretty much have to conclude that google’s technical savvy is overrated.

A useful tool for web developers

Ladies and gents… I haven’t written much lately, but then neither has Shakespeare. Fact is, work’s got me down, but as long as I have bills to pay there’s not a damn thing I can do about it, not in this economy anyway. Someone bring back Clinton so I can make more money while being able to show up for work at 10! Besides I think we can all agree that things tend to go smoother when the Prez is getting, er, serviced on a regular basis.

Enough of this maudlin talk, however — I have come up with a tool which does something neat and useful AND (surprisingly) doesn’t seem to have been done before. Now if you’re a web developer (as I am, obviously) you’ve probably wondered if there was a way to quickly spot all the references to pre-defined styles in an HTML file. This is not a difficult task — all one has to do is set up a perl script that can read an input file, run a regexp to find all the “class=something” (whether ‘something’ is in double-quotes or not) and output a text file with a list of the style names encountered along the way.

How’s that useful at all, you ask? Well, this can give you pointers as to what you can cut out of your CSS when you’re trying to optimize things. This is not usually a problem with personal sites, but it can be a bother in a company setting, esp. if you’re dealing with a CSS containing several hundred styles and your boss is wondering why it takes forever to load a page that uses it.

The script is in a zip file which you can obtain here: find_styles.zip. Why zip up a 13-line perl script? Mostly ’cause I need it to download and not execute, and my being at work prevents me from doing this properly otherwise (f*cking firewalls…).

Usage:

  1. Unzip the file (duh).
  2. From the location of the unzipped file (and of course assuming you have perl installed and working), type “find_styles.pl [location of file to check] [location of output file]”. The script will create the output file if it doesn’t already exist, provided you have the correct permissions for that location. It WILL overwrite any existing file, so careful with that. *NIX users can use “perl find_styles.pl [input file] [output file]”, and adjust the shebang line for the location of their perl install.
  3. Profit!

That’s it, pretty much. This script is free to anyone who finds it useful, and even to those that don’t. Just a couple of requests — if you really find it useful, feel free to send me money! Go to Paypal using the link on the right and donate whatever amount of money you feel it’s worth to you (as long as it’s over $0.32, ’cause otherwise it all goes to Paypal I think). Also if you make modifications to the script send me a copy, maybe you’ve come up with a neat feature I can also use!

Legalese stuff: this script is nominally copyrighted © 2003 CleverShark Corporation. However you may use it, copy it as many times as you want and use it in whatever way you see fit, as long as you’re decent enough to acknowledge my contribution to it 🙂