在提供JavaScript文件时,最好使用application / javascript或application / x-javascript [英] When serving JavaScript files, is it better to use the application/javascript or application/x-javascript

查看:653
本文介绍了在提供JavaScript文件时,最好使用application / javascript或application / x-javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

整个问题符合标题。并添加一些上下文:根据规范的说法,我不是在问什么是最好的,而是考虑到现在部署的浏览器组合,哪种方法效果最好。

The whole question fits in the title. And to add some context: I'm not asking what is the best according to what the specs are saying, but rather what works the best given the mix of browsers deployed nowadays.

一些数据点:


  • Google使用 text / javascript 表示使用过的JS

  • Google在Google文档上使用 text / javascript

  • Google使用 application / x-javascript 使用 Ajax库服务

  • Yahoo使用 application / x-javascript 来为他们的JS提供服务。

  • Yahoo对其主页上提供的JavaScript使用 application / x-javascript

  • Google uses text/javascript for the JS used on their home page.
  • Google uses text/javascript on Google Docs.
  • Google uses application/x-javascript to serve JavaScript files with their Ajax libraries service.
  • Yahoo uses application/x-javascript to serve their JS.
  • Yahoo uses application/x-javascript for the JavaScript served on their home page.

推荐答案


  • text / javascript 已过时

  • application / x-javascript 在决定搬到...时是实验性的。

  • application / javascript 是JS的当前官方MIME类型

    • text/javascript is obsolete
    • application/x-javascript was experimental while deciding to move to…
    • application/javascript is the current official MIME type for JS
    • 那说,浏览器经常忽略服务器发送的内容类型,并且非常注意类型属性(和有些人可能还没有认识到 application / javascript )。

      That said, browsers often ignore the content-type sent by the server and pay a lot of attention to the type attribute (and some may not yet recognise application/javascript).

      我的推荐:


      • 在服务器上使用应用程序/ javascript

      • 使用HTML 5并省略类型脚本元素的属性

      • Use application/javascript on the server
      • Use HTML 5 and omit the type attribute from script elements

      这篇关于在提供JavaScript文件时,最好使用application / javascript或application / x-javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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