6

Does anyone know of an online parser to automatically remove ALL comments EXCEPT for necessary conditionals? ie

<!--[if lt IE 9]>

I tried various forms of HTML5 minification but its buggy

Also saw these php solutions but would prefer to use an online parser if one already exists Removing all html comments except internet explorer comments using regex and php

Stripping HTML Comments With PHP But Leaving Conditionals

Community
  • 1
  • 1
Bachalo
  • 6,965
  • 27
  • 95
  • 189

2 Answers2

25

Here, just made one for you: http://jsfiddle.net/DerekL/BUVkS/show/

If you want to see the source, it is here: http://jsfiddle.net/DerekL/BUVkS/

Put your HTML code inside, then click remove comments.
It will then remove all comments and left with the conditionals.

(Used that PHP regular expression you put (the link) and I put it into JavaScript plus a little modification to match newlines)

/<!--(?!\s*(?:\[if [^\]]+]|<!|>))(?:(?!-->)(.|\n))*-->/g
Community
  • 1
  • 1
Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
3

I've found this online js comment removal tool that seems to work fine

http://james.padolsey.com/demos/comment-removal-js.html

opensas
  • 60,462
  • 79
  • 252
  • 386