Compressing Your HTML

If you are serious about trying to make your web pages load as fast as possible even on the slowest connection then every byte counts. You have probably already used all available means to compress your images as small as possible and are ready to consider how you might make your HTML smaller as well.

The obvious way to make your HTML smaller is to remove all unnecessary carriage returns, line feeds, and spaces. You can do this manually but it can take a lot of time. There is also the problem that the compressed HTML will be much harder for you to read (and hence edit) than your nicely formatted version.

The solution to compressing your HTML in the first place is to use a program to do the compression for you. HTML Compress is one program that I have found that will allow you to significantly compress your HTML files. The program can be customized so that you can keep backup copies of your original files as well as being able to decide which compressions to allow and which to disallow. By selecting to disallow the appropriate compressions you can produce a compressed output that is still a valid XHTML document (assuming that it was to start with).

Of course keeping uncompressed backup copies of your pages along with the compressed versions can lead to version control problems if you update a compressed version of the page at some stage and forget to apply the same changes to the uncompressed backup copy. To keep track properly you need to always work on the uncompressed version, run the compression, and then upload the updated copy of the compressed version.

Keeping two copies of your entire site also takes up more disk space than is really necessary (even though a 1000 page web site should not take up more than 10Mb per copy this is still wasted space because it is unnecessary).

The best solution is to use the compressed version of the pages as your master copy of the pages and decompress the pages when you need to update them. The easiest way to do this is to use HTML Tidy. This program is primarily intended to be used to validate your web pages against the appropriate standards but there is also a facility in the program to save a nicely formatted output copy of your page source. The options that you can customize here even allow you to specify a maximum line width so that you can set the line length to suit your editor.

So what you can do when you want to update one of your pages which you always keep in compressed form is to use HTML Tidy to decompress the file, use your favourite HTML editor to edit the file and make the changes to your page, use HTML Compress to recompress the updated file, and then use HTML Tidy again to validate the file to ensure compatibility with the largest number of browsers.

If you are still searching for the perfect editor to use to edit your web pages and you don't mind working with the HTML itself then one editor that deserves consideration is CSE HTML Validator which can generate the correct XHTML tags and also validate your page. Many other editors only support HTML 4.0 tags which are now two generations of the standards out of date (the latest standard is XHTML 1.1 which replaces XHTML 1.0 which replaced HTML 4.0 quite some time ago). Using an editor such as this one that will validate your pages for you after you edit them will also save you the trouble of running the extra validation step following the compression (once you have confirmed that the compression options you are using do not convert your valid code into invalid code).

Compressing your HTML, CSS, and Javascript (which HTML Compress can also handle) may only reduce your page sizes by a couple of hundred bytes each but every little bit counts in making your pages faster loading. You also have the added advantage that the compressed source is harder to read than a nicely formatted version of the same page source which will make it less likely that others will consider stealing your page content (unless they know about HTML Tidy).


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow