function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
amoldavskyamoldavsky 

Server side comments

Hey guys,

 

Am I right by concluding that VisualForce pages do not have server side comments?

Something from the Java (JSP pages) world would be <%-- my comment --%> or <% /* some comment */ %>

This is very different from an HTML comment such as <!-- comment --> by the fact that the client still has to download what's ever in it.

 

I have found this old thread:

http://boards.developerforce.com/t5/Visualforce-Development/Visualforce-Server-Side-Comment-Syntax/td-p/98450

 

Which concluded with no asnwer, tried to google but was unsuccessful.

If I use the <!-- --> syntax VisualForce just masks whatever characters are in those comment tags.

This is still a problem because I do not want the client to download junk.

 

Is there a way to make server side comments? If not, then maybe a hack to wrap the comment in some custom apex block element?

 

Below is what I see in the HTML source using the <!-- --> syntax:

 

 <!--
*****************************************
**********************
******************************
***********************************************************************************
**
**********
******
******************************************************************************************
***********************************************************************************
******
********************************************
**************************************************************
********************************************
*******************************
**************
******************************************************
**************************************************************************
******************************************************************************
**************************
********************
*******
********
************
*********************************
*****************************************
*******************************************************************************
****************************************************************************
***************************************************************************************
*************************************
**************************
********************
********
*******
***************************************
*******************************************
****************************************************************************
***************************************************************************************
*************************************
*******
******************
*******
*****
****
***
******
*-->

 

 

Thank you!

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

Nope, you can't make server-side comments that won't be downloaded as masked characters. Before you worry too much about that, you should consider that salesforce.com connections are gzipped, and they'll compress down to absolutely nothing (not literally, but so small you won't notice). Besides, a typical SFDC page is almost 2 MB of uncompressed data, so the extra bytes won't really matter in the grand scheme of things.

All Answers

sfdcfoxsfdcfox

Nope, you can't make server-side comments that won't be downloaded as masked characters. Before you worry too much about that, you should consider that salesforce.com connections are gzipped, and they'll compress down to absolutely nothing (not literally, but so small you won't notice). Besides, a typical SFDC page is almost 2 MB of uncompressed data, so the extra bytes won't really matter in the grand scheme of things.

This was selected as the best answer
amoldavskyamoldavsky

Ok so I found a small hack for this...

 

You can do this...

<apex:variable var="unimifiedCoreJS" value="" rendered="">
  my comments blablabla...
</apex:variable>

 

You can also make it a component and do something like this in you VS pages:

<c:comment> my comments blablabla </c:comment>

 

sfdcfoxsfdcfox

Nice hack. It certainly does work, since you're then not hiding comments directly. You could also use any Visualforce elements that accepts text and has the rendered attribute, as far as that goes... apex:outputPanel, apex:outputLabel, apex:outputText, apex:pageBlock, and most other visual elements behave this way. The only problem with this workaround is that one would be cluttering the code unnecessarily, as most IDEs won't syntax-highlight them as actual comments, etc. That aside, I'm surprised I didn't think of it sooner myself...

amoldavskyamoldavsky

 

All your points are absolutely valid and I totally agree with all of them. The problem I was trying to solve, and maybe I should of explained the context first, is hidding unminified JS and CSS. The app will have quite a bit of JS and CSS going forward and we don't want to waste HTTP requests to get these resources. What I am doing is breaking JS namespaces into components (like JSPF static includes) and then minify each but keeping the unminified version commented out for easy developement.

 

Either way, problem solved! :)

 

Thanks for your help