Sep 20 2007
Trimming comments in HTML documents using Apache Ant
This short article, explaining how to trim unnecessary code (comments, empty lines) from HTML documents, is a follow-up to an article published a couple of weeks ago on this blog: Building Web Applications With Apache Ant. Basically, the idea is to use Ant’s optional replaceregexp task as shown below:
Update: Use this code very carefully as it is dangerous territory (Thanks to my co-worker Ryan Grove for pointing out some of the shortcomings)
Awesome. Keep the ant scripts coming they are great.
[...] Ant Homepage Phing Homepage Building Web Applications With Apache Ant - Julien Lecomte Trimming comments in HTML documents using Apache Ant - Julien Lecomte Improve Your Build Process with Ant - ONLamp Ant sucks for FTP deployment - What [...]
[...] desconocido wrote an interesting post today!.Here’s a quick excerptfrom HTML documents, is an update to an article published a couple of weeks ago on this blog: Building Web Applications With Apache Ant. Basically, the idea is to use Ant’s optional replaceregexp task as shown below: … [...]
How do you prevent the regex from removing Javascript enclosed in HTML comments in order to hide it from browsers, which have Javascript disabled?
I fiddled around a lot but never managed to get ant ignore comments which end with //–>. It always results in an infinite loop.
@Steve
Do not wrap inline JavaScript code inside HTML comments. Nobody uses Netscape 1 anymore…
Here’s one for removing console.log within a combined yui compressed file.
<replaceregexp file="my_combined_file.js" match="(console\.log\(.*\))" flags="g" replace="\/\/\1"></replaceregexp>