Very short trick: making invisible HTML comments

Comment HTML is a practice during the early stages of Web development, however the commented code remains visible on the page, even if it is ignored by the browser. By selecting "View Source" or "View Code" from our browser, we will be able to see it. The comments apply to HTML using the syntax:

1
2
3
4
5
p > < p > Visible </ p >
<! -
I'm a comment
->
p > < p > Visible </ p >

è possibile inserire – quindi commentare – sezioni HTML: Within the marker <!-- and --> you can enter - then comment - HTML sections:

1
2
3
4
5
6
7
p > < p > Visible </ p >
<! -
<div class="right">
Commented <p> </ p>
</ Div>
->
p > < p > Visible </ p >

, è visibile perchè inviata comunque dal web server a noi client. As mentioned above, the piece of code commented out, the one between the markings <!-- and --> , because it is visible, however, sent to us by the web server client. This definitely produces two disadvantages:

  • HTML code is visible, when I want to remain hidden because it concerns demo or sections to be developed
  • The commentary sections - whether full-bodied - unnecessarily weigh down the page, they are sent but not processed

A little trick / advice if you provide a server-side language like PHP or ASP, is to use the procedures that the latter comment to comment HTML. Returning to the examples above, if you have PHP you could use:

1
2
3
4
5
6
7
p > < p > Visible </ p >
<? Php / *
"right" > < div class = "right">
p > < p > Commented </ p >
</ div >
* /?>
p > < p > Visible </ p >

, si usa la coppia <?php /* e */ ?> . In practice, instead of using the pair <!-- and --> , we use the pair <?php /* and */ ?> .
In this case, the page is processed by your server-side-language (PHP or ASP) before being sent to the browser-client. In doing so the comment is to disappear in our PHP page and not sent to the browser but, of course, always present in the source. :)

There are no comments for this post

Leave a comment

XHTML TAG PERMIT: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL 


Stop SOPA