Valhalla Legends Forums Archive | Web Development | Comments

AuthorMessageTime
Grok
Is there a way to put comments in an HTML page that do not get sent by the web server to the client?
April 27, 2004, 3:40 PM
synth
If you were using ASP on that page, you could put them inside ASP tags.

Like so:

[code]<%
' This code was written by me.
%>[/code]
Then continue with the rest of your page. The comment would be visible to you (and to anyone else who has the source), but to the average user, it's invisible.

That's the only way I know of effectively hiding anything from "View Source".

Are you able to use ASP in your pages, or will this be a completely static web page?
April 27, 2004, 5:16 PM
Grok
I'm not trying to hide anything from view source. I want to put comments in my javascript but without the bandwidth penalty of transmitting them to the client.
April 27, 2004, 6:38 PM
hismajesty
Is [code]<!-- comment -->[/code] what you're looking for?

Edit: Nevermind, re-read your post. I overlooked the part about *not* sending it to the end user.
April 27, 2004, 7:15 PM
iago
As far as I know about how html works, the server reads the file and sends the whole thing without caring. It's possible that certain webservers have extensions to do special things, I would recommend you look at the documentation for the specific webserver you're using.
April 27, 2004, 9:01 PM
peofeoknight
In asp or asp.net
[code]<% 'comment %>[/code] would not send to the client. This was mentioned above by synth, what would be the problem with this solution? You can obviously mod the file types that are running on your server and end up with pages that have a .html extention but have server side scripts being executed when they are requested, the draw back is that doing this will mean that all html pages will have to be read by the server. It is going to be different to change extentions on apache iis and other servers though, but it could easily be found by doing a google.
[code]<?php
// I am not a php user, but this is what a single line php comment looks like
?>[/code]
April 27, 2004, 9:55 PM
Myndfyr
If you really want to get creative, I would suggest something like this...

Set your ASP interpreter (assuming IIS) to also handle .jsx files. In any Javascript files you want to comment in, do something along the lines of...

[code]
<% @LANGUAGE="JScript" %>
function doStuff()
{

}
<%
// comments go here that won't be sent to the client
// they must be commented, or the ASP interpreter will try to do something with them.
%>
function doMoreStuff()
{
doStuff();
}
[/code]

Then set your code to:

[code]
<script language="JavaScript" src="MyJavascript.jsx" />
[/code]

Also, you don't need to worry about bandwidth so much if you have caching enabled on your server and you put your Javascript into a separate .js file. Then, the server only transmits your code once until it is updated.
April 28, 2004, 12:00 AM
synth
[code]
<%
' Comment
%>
[/code]

This would not transmitted to the client. Remember that the server executes the ASP code and leaves all code inbetween ASP tags out, and also that compilers, in general, discard comments.

Therefore, the comment would be left out of the source. Obviously, it is hidden from view, but more importantly, it is not transmitted to the client, therefore no bandwidth is used.

EDIT: But, if you're set on JavaScript, you could try Myndfyre's solution.
April 28, 2004, 1:37 AM
St0rm.iD
If using CF...
[code]
<!--- notice the three dashes --->
[/code]
April 28, 2004, 1:58 AM
Grok
Thanks guys, but I already know how to do it in ASP. My question was HTML. But it seems the answer is that no server-side processing is performed on HTML pages without extensions.
April 28, 2004, 2:42 AM
peofeoknight
[quote author=Grok link=board=22;threadid=6504;start=0#msg57214 date=1083120133]
Thanks guys, but I already know how to do it in ASP. My question was HTML. But it seems the answer is that no server-side processing is performed on HTML pages without extensions.
[/quote] yep, the only way to keep that html format with server side processing is to have the server reguard html files as asp files by changeing the extentions. I am not actually sure how to do it on iis.... hold on. Humm I thought it could be done when I play around under the headers tab but this doesnt seem to be working... poo.
April 28, 2004, 4:13 AM
Adron
[quote author=Grok link=board=22;threadid=6504;start=0#msg57214 date=1083120133]
Thanks guys, but I already know how to do it in ASP. My question was HTML. But it seems the answer is that no server-side processing is performed on HTML pages without extensions.
[/quote]

You can select to do server-side processing on HTML pages and have shtml. There you might be able to insert some text like this:

<!--#echo tag="LAST_MODIFIED" comment="Try inserting some text here and see if the server accepts the line anyway without passing the comment to the client!" -->
April 28, 2004, 10:47 AM

Search