Click here to Skip to main content
15,173,839 members
Articles / Programming Languages / C++
Posted 7 Jun 2000

Tagged as


24 bookmarked

OptimizeHTML: A Tool to Optimize HTML Files

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
7 Jun 2000
A simple script to reduce the size of a HTML source
This little VBScript application strips unneeded characters from your HTML files.

Sample Image - OptimizeHTML.gif


Today's HTML editors are very easy to use, they support visual editing as well as syntax highlighting and auto-formatting of HTML source, for both the beginner and the advanced user's happiness. But things like auto-indenting make your files bigger and bigger, so that you may want to reduce the download time of your pages. Here it comes, this little script.

This little VBScript application strips unneeded characters from your HTML files. The result is not handy to edit again, so this script should be used as the last step before uploading. However, reloading the file into your favorite auto-formatting editor should bring it again to its previous state.

OptimizeHTML Usage

There are several ways to use this script:

  • You may double-click on it or execute from the Shell.

    The main dialog will appear asking for some files to optimize. You may specify either an absolute or a relative path. If the filename part of the path is a '*' (asterisk) character, it will process all the .htm and .html files in the given directory (current directory, if none is specified). It will not recurse subdirectories.

  • You may drop some files on it or give command line arguments.

    The program will process each file dropped (or from the command line).

If more than one file is to be processed, the script will ask for confirmation.

You may personalize the program's behavior and even the language. These are overridable options:

  • VBScript
    'be careful with this
    Const REMOVE_COMMENTS = False
    'removes some META tags used by editing applications
    Const REMOVE_PROGID = False
    'try with this option enabled first
    Const MAKE_BACKUPS = True
  • REMOVE_COMMENTS removes the comments enclosed in the <!-- --> tag
  • REMOVE_PROGID removes <META NAME="GENERATOR" ... > and <META NAME="ProgId" ... > tags
  • MAKE_BACKUPS makes a backup copy of each file processed, appending a .bak to the filename

And these are the localizable strings:

Const INPUT_FILE = "HTML file to optimize:"
Const INPUT_TIP = "Tip: 'path\*' means all .htm .html files" & _
                  " in given path (default is current path)"
Const PROCEED_MSG = "Optimization of all .htm .html files in folder:"
Const PROCEED_ASK = "Proceed?"
Const PROCEED_CMD1 = "Optimization of "
Const PROCEED_CMD2 = " files from command line."
Const COMPLETE_MSG = "Optimization completed."
Const ERR_NOTFOUND = "File does not exist."

You may wish to create a shortcut to OptimizeHTML.vbs in your SendTo directory and it will optimize all the files you send to it.

More on HTML Validation and Optimization

If you want to know more about HTML and related technologies, this is a site you must visit: The World Wide Web Consortium.

You may also take a look at the W3C Open Source Software in that same page and try the good HTML Tidy utility by Dave Ragett. Here is an excerpt from his page:

  • "When editing HTML, it's easy to make mistakes. Wouldn't it be nice if there was a simple way to fix these mistakes automatically and tidy up sloppy editing into nicely laid out markup? Well now there is! Dave Raggett's HTML TIDY is a free utility for doing just that. It also works great on the atrociously hard to read markup generated by specialized HTML editors and conversion tools, and can help you identify where you need to pay further attention on making your pages more accessible to people with disabilities."

If you want to validate your HTML pages, you may use the HTML Validation Service, always from the W3C site.


I hope you will find this script useful for your HTML editing. Please, note that this script only strips some characters from the specified files, it can't validate them.

If you improve the code, please let me know and make it available to other people. For any comments, suggestions or critics, use the space below.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


About the Author

Paolo Messina
Technical Lead RoboTech srl
Italy Italy
Paolo began programming at the age of 9 with a glorious Olivetti M24 (i8086) and GW-BASIC, then he played a bit with Turbo C, Turbo Pascal and Assembly (using the MS-DOS Debug). Quick BASIC and Visual Basic shortly followed, until he learned C++ in College. He tought himself MFC and Windows programming, along with some DHTML and Javascript.

Always attracted by low-level programming and Assembly, he started to appreciate the joys of templates and STL while working for his Master Thesis. For seven months he was playing with airplanes and automatic control at the Unversity of Illinois at Urbana-Champaign, where he first met QNX and embedded systems.

In his job experience he learned Java to develop user interfaces and graphical editors, and re-discovered the Eclipse IDE that he had used in its early versions with the QNX SDK. He also deepened his knowledge of Linux and embedded systems, microcontrollers firmware and embedded voice recognition, while also practicing electronics design.

He graduated in Computer Engineering (Ingegneria informatica) at the University of Pisa, Italy, in December 2003. Currently working for an electronics and robotics company (

He lives in Peccioli (Pisa) and Follonica (GR), Italy.

Comments and Discussions

QuestionOnly whitespace compression? Pin
29-Sep-01 23:24
suss29-Sep-01 23:24 
GeneralI need an HTML Formatting tool Pin
Alvaro Mendez11-Jul-00 9:40
MemberAlvaro Mendez11-Jul-00 9:40 
GeneralRe: I need an HTML Formatting tool Pin
Paolo Messina14-Jul-00 4:18
professionalPaolo Messina14-Jul-00 4:18 
GeneralRe: I need an HTML Formatting tool Pin
Anonymous12-Sep-03 6:31
MemberAnonymous12-Sep-03 6:31 
GeneralRe: I need an HTML Formatting tool Pin
Ted Crow1-Oct-00 11:14
professionalTed Crow1-Oct-00 11:14 
GeneralBatch mode is a good idea Pin
Stephane Rodriguez12-Jun-00 0:48
MemberStephane Rodriguez12-Jun-00 0:48 
GeneralRe: Batch mode is a good idea Pin
Paolo Messina12-Jun-00 8:26
professionalPaolo Messina12-Jun-00 8:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.