为什么再使用X-UA兼容的IE = Edge? [英] Why use X-UA-Compatible IE=Edge anymore?

查看:182
本文介绍了为什么再使用X-UA兼容的IE = Edge?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近参加了几个在线课程,我仍然看到一些教师默认在文档的顶部添加以下元标记:

 < meta http-equiv =X-UA-Compatiblecontent =IE = edge> 

这种想法似乎与<一样重要且有用; meta charset =UTF-8>



但为什么?



根据

  • 它只是为了解决问题而设计用于临时使用



  • 来自微软的报价(强调我的): / p>

    它减慢了初始页面渲染...


    当Internet Explorer遇到X时-UA兼容的META标签,它使用指定版本的引擎启动。 这是性能提升,因为浏览器必须停止并重新开始分析内容。


    它只是专为临时使用而设计...


    X-UA-Compatible指令是允许应用程序在最新的Internet Explorer版本中运行的工具在对应用程序进行更新时


    如果您绝对需要,可以使用更好的方法来实现X-UA兼容性......


    最佳做法是支持X-UA的HTTP标头。将指令添加到响应头中告诉Internet Explorer在解析内容之前要使用哪个引擎。这必须在网站的服务器中配置。


    现在只有IE11是在现代操作系统上正式支持 ...


    从2016年1月12日开始,只有支持的操作系统可用的最新版Internet Explorer才会获得技术支持和安全更新。 Internet Explorer 11 是Internet Explorer的最新版本,并将继续在 Windows 7,Windows 8.1和Windows 10 上获得安全更新,兼容性修补程序和技术支持。


    实际上,包含 X-UA-Compatible 元标记的唯一原因在您的HTML中是覆盖用户的网站兼容性视图设置。在几乎所有情况下,用户都不会更改这些设置(为什么会这样?)。



    简而言之:不要这样做。


    I've taken several online courses lately and I still see some instructors add the following meta tag to the top of their documents by default:

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    

    The thinking appears to be that this is just as important and useful as <meta charset="UTF-8">.

    But why?

    According to Microsoft's Modern.ie documentation it's "best practice" which "ensures Internet Explorer uses the latest engine". Ok, fair enough.

    However, if you follow the flow diagram on MSDN it clearly shows that a document without `X-UA-Compatible information is forwarded to the user's "Compatibility View" preferences, and if that's not set then just follow the !DOCTYPE declaration.

    In other words, unless the user has some Compatibility View settings in place, IE will just follow your !DOCTYPE and use the latest standards mode of your browser for rendering anyway... No need for a X-UA-Compatible IE=Edge statement at all.

    As MSDN says: "Use the HTML5 document type declaration to enable edge mode".

    So in what circumstances is X-UA-Compatible IE=Edge needed?

    解决方案

    As @David's answer points out, unless you're hosting a site in the "Local Intranet" zone, there is very little reason to include <meta http-equiv="X-UA-Compatible" content="IE=edge"> in your webpages, and (according to Microsoft's best practice recommendations) absolutely no reason to include it in the HTML. (You should place it in your server config or site headers -- not in the HTML itself.)

    If you are considering using X-UA-Compatible anywhere in your project, you should remember that Compatibility View only affects IE8, 9 and 10. It was only introduced in IE8 and was disabled in IE11.

    Also be aware that IE11 is the only officially supported version of IE at this time. All older versions should be considered insecure.

    If that wasn't enough reason to convince you not to use it, consider that Microsoft state that IE8 and above already automatically render in Standards Mode when a <!DOCTYPE is present, making it even more pointless.

    You can see for yourself the flow that IE takes to decide what document mode to use:

    As you can see, if no X-UA-Compatible meta tag or HTTP header is present, it checks the user's "Compatibility View" settings. If the user doesn't have any for your website, IE then checks for the presence of a <!DOCTYPE declaration. If it finds one it automatically uses the latest Standards Mode (aka "EmulateIEx"). If it doesn't, it reverts to Quirks Mode.

    Even more reasons why you shouldn't use the "X-UA-Compatible" meta tag:

    Quotes from Microsoft (emphasis mine):

    It slows initial page render...

    When Internet Explorer encounters the X-UA-Compatible META tag it starts over using the designated version's engine. This is a performance hit because the browser must stop and restart analyzing the content.

    It was only ever designed for temporary use...

    The X-UA-Compatible directive is a tool to allow applications to work in the latest Internet Explorer version while updates are made to the application.

    There's better ways of implementing X-UA-Compatible if you absolutely need it...

    The best practice is an X-UA-Compatible HTTP Header. Adding the directive to the response header tells Internet Explorer what engine to use before parsing content begins. This must be configured in the web site's server.

    Now only IE11 is officially supported on modern operating systems...

    Starting from 12 January 2016, only the most current version of Internet Explorer available for a supported operating system will receive technical supports and security updates. Internet Explorer 11 is the last version of Internet Explorer, and will continue to receive security updates, compatibility fixes and technical support on Windows 7, Windows 8.1 and Windows 10.

    In reality, the only reason to include the X-UA-Compatible meta tag in your HTML was to override a user's "Compatibility View" settings for your website. In almost every case the user will not have changed these settings (why would they?).

    In short: Don't do it.

    这篇关于为什么再使用X-UA兼容的IE = Edge?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆