Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to prevent standard HTML comments from showing up in source code?

Tags:

comments

html

php

I'm going to assume the answer is 'no' here, but since I haven't actually found that answer, I'm asking.

Quite basically, all I want to do is leave some HTML commenting in my files for 'author eyes only', simply to make editing the file later a much more pleasant experience.

<!-- Doing it like this --> leaves nice clean comments but they show up when viewing the page source after output.

I am using PHP, so technically I could <?PHP /* wrap comments in PHP tags */ ?> which would prevent them from being output at all, but if possible I'd like to avoid all of the extra arbitrary PHP tagging that would be needed for commenting throughout the file. After all, the point of commenting is to make the document feel less cluttered and more organized.

Is there anything else I could try or are these my best options?

like image 236
vertigoelectric Avatar asked Sep 26 '12 21:09

vertigoelectric


People also ask

How do I hide comments in HTML code?

To create hidden comments in HTML, add <! --- tag and end it with -- >. Whatever comes inside it is hidden. These comments are beneficial for those who need to refer the code again, which allow them to easily understand the code.

Can we hide content using the comment HTML?

Hide Inline ContentComments can be used to hide parts in the middle of the HTML code.

Why do Web developers leave comments in HTML code?

Like comments in CSS, adding comments to your HTML can help you write and organize the backend of your webpage. You can add comments to explain your code, which will make it easier to edit in the future or to work with other developers. You can also use comments to simplify your debugging efforts.

Why HTML comments can help document your HTML source code?

It is a good practice to add comments into your HTML code, especially in complex documents, to indicate sections of a document, and any other notes to anyone looking at the code. Comments help you and others understand your code and increases code readability.


1 Answers

No, anything in html will show up.

You could, have a script that parses the code, and removes the comments, before it puts it up on the server, and then you would have the original, and the uncommented source.

A tool to accomplish this: http://code.google.com/p/htmlcompressor/

like image 197
nycynik Avatar answered Sep 20 '22 00:09

nycynik