tirsdag den 11. november 2014

Why you shouldn't just hardcode X-UA-Compatible meta tag in your layout

Sometimes, people either hardcode the X-UA-Compatible meta tag in the <head> section of the page, or in the web.config file as a custom header.

I have seen this a few times now, and every time it breaks something (especially with versions of Sitecore before 7.2) .

The problem is, that doing it this way, you prevent Sitecore from changing it when it is needed for it's own tools to work (like the page editor).

Instead, what you should do, is add the following code to the Page_Load function of your layout:

if (Sitecore.Context.PageMode.IsNormal)
{
    Response.AddHeader("X-UA-Compatible", "IE=edge,chrome=1");
}

Now, the X-UA-Compatible indication is still sent to the browser, which knows how to handle it (since it can be told this both using headers and meta tags) - but both Preview and the Page Editor works like they should, since it doesn't get set.

Ingen kommentarer:

Send en kommentar