HTML Comments and IE Conditional Comments
Visualforce removes most HTML and XML comments from the page before rendering, without processing their contents.
Internet Explorer conditional comments, however, will be rendered, allowing you to include IE-specific resources and meta tags.
Internet Explorer conditional comments are most commonly used to address browser compatibility issues, generally with older
versions of IE. Although conditional comments work wherever they are used on the page, they are frequently placed inside
the page’s <head> tags, where they can be used to include version-specific stylesheets or JavaScript compatibility “shims.”
To place conditional comments inside a page’s <head> tag, disable the standard Salesforce header, sidebar, and stylesheets,
and add your own <head> and <body> tags:
<apex:page docType="html-5.0" showHeader="false" standardStylesheets="false">
<head>
<!-- Base styles -->
<apex:stylesheet value="{!URLFOR($Resource.TestStyles, 'css/style.css')}"/>
<!--[if lt IE 7]>
<script type="text/javascript"
src="{!URLFOR($Resource.TestStyles, 'js/obsolete-ie-shim.js')}>
</script>
<link rel="stylesheet" type="text/css"
href="{!URLFOR($Resource.TestStyles, 'css/ie-old-styles.css')}" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css"
href="{!URLFOR($Resource.TestStyles, 'css/ie7-styles.css')}" />
<![endif]-->
</head>
<body>
<h1>Browser Compatibility</h1>
<p>It's not just a job. It's an adventure.</p>
</body>
</apex:page>
Visualforce doesn’t support or evaluate Visualforce tags, for example, <apex:includeScript/>, within standard HTML
comments. However, it will evaluate the following expressions within IE conditional comments:
• Global variables, such as $Resource and $User
• The URLFOR() function
Visualforce removes most HTML and XML comments from the page before rendering, without processing their contents.
Internet Explorer conditional comments, however, will be rendered, allowing you to include IE-specific resources and meta tags.
Internet Explorer conditional comments are most commonly used to address browser compatibility issues, generally with older
versions of IE. Although conditional comments work wherever they are used on the page, they are frequently placed inside
the page’s <head> tags, where they can be used to include version-specific stylesheets or JavaScript compatibility “shims.”
To place conditional comments inside a page’s <head> tag, disable the standard Salesforce header, sidebar, and stylesheets,
and add your own <head> and <body> tags:
<apex:page docType="html-5.0" showHeader="false" standardStylesheets="false">
<head>
<!-- Base styles -->
<apex:stylesheet value="{!URLFOR($Resource.TestStyles, 'css/style.css')}"/>
<!--[if lt IE 7]>
<script type="text/javascript"
src="{!URLFOR($Resource.TestStyles, 'js/obsolete-ie-shim.js')}>
</script>
<link rel="stylesheet" type="text/css"
href="{!URLFOR($Resource.TestStyles, 'css/ie-old-styles.css')}" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css"
href="{!URLFOR($Resource.TestStyles, 'css/ie7-styles.css')}" />
<![endif]-->
</head>
<body>
<h1>Browser Compatibility</h1>
<p>It's not just a job. It's an adventure.</p>
</body>
</apex:page>
Visualforce doesn’t support or evaluate Visualforce tags, for example, <apex:includeScript/>, within standard HTML
comments. However, it will evaluate the following expressions within IE conditional comments:
• Global variables, such as $Resource and $User
• The URLFOR() function