Find your content:

Search form

You are here

meta and script tags before standard Salesforce tags in head


Is it possible to include script and meta tags before the the standard salesforce tags?

The standard head is like the following:

<script src="/jslibrary/1351189248000/sfdc/JiffyStubs.js"></script>
<style type="text/css"></style>
<script src="/jslibrary/1351189248000/sfdc/SfdcCore.js" type="text/javascript">
</script><script src="/static/111811/js/picklist.js" type="text/javascript"></script>
<script src="/jslibrary/1351189248000/sfdc/VFState.js" type="text/javascript"></script>

Now first my modifications follow:

<link class="user" href="/resource/16456546546/Foo/css/main.css" rel="stylesheet" type="text/css">

<meta http-equiv="PRAGMA" content="NO-CACHE">
<meta http-equiv="Expires" content="Mon, 01 Jan 1990 12:00:00 GMT">
<meta content="IE=EmulateIE8" http-equiv="X-UA-Compatible">
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<script src="/resource/1354808845000/SCRM/script/jquery.min.js" type="text/javascript"></script> <script src="/resource/1354546456/Foo/script/jquery-ui.min.js" type="text/javascript"></script>

 <title>Site Login</title> </head>

I need to be able to insert something before the first Salesforce standard script tag. E.g. according to

Attribution to: k_o_

Possible Suggestion/Solution #1

if you are referring to VisualForce pages, I have had to do this quite a few times. I usually keep all such tags just after the <Apex:page> tag.

Something like:

<apex:page sidebar="false" showheader="false" standardstylesheets="false">
<apex:includeScript value="{!URLFOR(................)}" />
<apex:stylesheet value="{!URLFOR(...................')}" />


         <title>Customer Portal Home</title>



Attribution to: Richard N

Possible Suggestion/Solution #2

Using the <apex:includeScript /> and <apex:stylesheet /> tags instruct the VF parser to place the contents into the rendered document <head> block. It does not matter where these tags are physically placed in the VF (or component) markup, the result will be a script or stylesheet reference within the <head> block at a known location.

Scripts are normally injected into the markup just after SfdcCore.js and the stylesheet is injected just after the SalesForce 'theme' stylesheet definition.

Unfortunately, this same feature of conveniently rendering items into the head doesn't exist for <meta> tags within the document using an apex tag. If you define the meta tags within the body, you're creating invalid markup per the spec, though most browsers tolerate this without complaint.

Scripts which have been included using the <apex:includeScript /> tag more than one time in the VF markup will not include multiple references to the script in the rendered markup. I presume this uniqueness aspect exists in the <apex:stylesheet /> tag as well.

As a side-note, be aware that adding <html> and <head> and <title> tags directly in your VF markup may result in stray tags in the rendered document (multiple html or head tags, etc). This would also be considered invalid markup.

Depending on what your requirement is to 'insert something before the first Salesforce standard script tag', you can use JavaScript to insert elements before it in the DOM like so:

var js = document.createElement('script');
js.src = 'myscript.js';
var first = document.getElementsByTagName('script')[0];
first.parentNode.insertBefore(js, first);

Attribution to: Mark Pond

Possible Suggestion/Solution #3

To prevent invalid markup through having multiple head tags, and to be able to inject content into the head tags of a visualforce page I suggest you look at the apex:page attribute of applyhtmlTag. If you set this to false, you can manually define the head tags yourself and add whatever you need between them.

This also allows you to add meta tags at build time rather than after the page is loaded.

Attribution to: CloudHugger
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content