views:

63

answers:

3

Hi All, At the time of development we tend to put lot of comments in the HTML pages or may be comment out some stuff as per customization request of end user. When dealing with hundreds of pages how to ensure that all commented text is removed before final deployment. Cause packaging pages with comment for everyone else to see ,is I assume a bad practice. So any good tool that can be incorporated in build script to perform these ?

A: 

If you're not using any type of server-side scripting you have to strip them out manualy.

If you use server-side scripting you can use a regular expression. just google to "remove html comments" and your server-side scripting language.

Tim
Javascript obviously won't work, as the end user can still "view source" to find them.
S Pangborn
your right, stupid me.
Tim
+2  A: 

HTML Tidy should do the job.

http://tidy.sourceforge.net/docs/quickref.html#hide-comments

S Pangborn
HTML Tidy will screw up your HTML file source code completely. I would not reccomend it if you are interested just in removing comments.
Marco Demajo
@Marco Demaio: What does "screw up" mean? I've never heard of Tidy rendering a page nonfunctional.
Chuck
@Chuck: I used the wrong term, i didn't mean HTML Tidy makes page non functional, but for examples: DOCTYPE is removed or changed automatically or splitted into two lines, META are splitted into two lines too, it does many other optimizations that final users might not be interested in. Here calvinsconner is asking only to remove comments not to change/optimize all the HTML source code. I know you can play with settings to disable some of the optimiziations, but there are thousands of settings to play with. I believe Absolute HTML Compressor is the way to go in order to removing HTML comments.
Marco Demajo
+1  A: 

I use this: Absolute HTML Compressor

It's great and it does NOT change/optimize source code, it does only what you ask it to do. I personally ask it only to remove comments and white spaces at the beginning of each line. From command line or in batch file I do:

ahc "path/file.html" -y- -l- -q- -w+ -t- -c+ -d- -m- -b-

WARNING: -b- option (that I used above) disables backup so the file will be overwritten.

BTW: it has got also a very nice GUI to use it without command line if you want.

Marco Demajo