开发者

Is it safe to comment out large chunks of HTML code?

开发者 https://www.devze.com 2023-03-01 16:16 出处:网络
Is it generally safe to enclose large chunks of HTML (containing form elements, script tags, etc) with <!-- and -->, or will this 开发者_开发知识库cause problems in some browsers?

Is it generally safe to enclose large chunks of HTML (containing form elements, script tags, etc) with <!-- and -->, or will this 开发者_开发知识库cause problems in some browsers?

I know its not ideal for source control, but I'm really interested as to whether it will actually cause issues in browsers or not.

Thanks.


Normally it's safe... except sometimes. I guess it's not safe, then :-)

There might be some problems, specially if there are scripts enclosed: for one thing, a comment should not include any -- (ref). Some people even advise against having a > inside a comment (ref), but I'd say that's too extreme.

Above all: you cannot nest comments. So, if you html code already has "real" comments, you are in trouble.

In general, I'd say that using html comments to "comment out" fragments of code is not good practice.


To the best of my knowledge all modern and semi-modern(*cough*IE6*cough*) handle commenting out huge chunks perfectly fine. (Can't test it right now because I don't have a WinXP machine at hand)


Source control is what comes to mind however there is no limitation that comes to mind to determine how much code you can comment out.

Although extremely sloppy and not recommended for readability, it can be done. Comments should always be used to enhance readability rather than hinder.

0

精彩评论

暂无评论...
验证码 换一张
取 消