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.
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:
Const Const 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.