How to ensure <meta http-equiv="X-UA-Compatible" > is placed in first place inside <head> element?

1.1k Views Asked by At

I'm trying to solve the following: When I access my application in IE, it automatically opens in IE7 Document Mode, instead of opening in IE9. After some research I found some info like in this site: https://code.i-harness.com/en/q/f10390, from which I understand I must place

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"></meta>       

in first place inside < head> element. Which I believed I was doing. However when the page is rendered all elements I defined in my template, inside h:head, are being placed after other css and js that bootsfaces need (jquery..etc).

I even added as follows, in web.xml, since it seamed to be necessary to override the placement of

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"></meta>       


<context-param>
  <param-name>BootsFaces_USE_VIEWPORT</param-name>
  <param-value>false</param-value>
</context-param>

My template:

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"  
   xmlns:h="http://java.sun.com/jsf/html"   
   xmlns:f="http://java.sun.com/jsf/core"   
   xmlns:ui="http://java.sun.com/jsf/facelets"  
   xmlns:b="http://bootsfaces.net/ui"       
   xmlns:ds="http://deltaspike.apache.org/jsf">
   <f:view contentType="text/html" encoding="UTF-8" >
     <h:head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"></meta>       
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>My System</title>
        <h:outputScript library="mySystem" name="js/mySystem.js" position="last" />
        <h:outputStylesheet library="mySystem" name="css/mySystem.css" position="last" />
     </h:head>
     <h:body>
       <ds:windowId />
          ...

Is there anyone who is able to enlighten me on how can I achieve the desired opening in IE9 document mode, or how can I achieve to generate html where < meta http-equiv .../> is the first line inside the head element. Thanks in advance.

1

There are 1 best solutions below

0
rui On

Well I'm going to answer, once I found a solution. Not sure if it is the best one:

I managed to force the <meta> node to be in first place, using

<f:facet name="first">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
</f:facet>

I found the answer here. How to make a meta tag the first one in the <head> section?