Javascript MIME类型 [英] Javascript MIME Type

查看:251
本文介绍了Javascript MIME类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于这个问题: jQuery代码无法在IE中运行

所以 text / javascript 用于HTML文档,因此Internet Explorer可以理解它。但我想知道,你什么时候会使用 application / javascript ,更重要的是,你为什么要用它代替 text / javascript

So text/javascript is used in HTML documents so Internet Explorer can understand it. But I'm wondering, when would you use application/javascript, and more importantly, why would you use it instead of text/javascript?

推荐答案

理论上,根据 RFC 4329 application / javascript

原因它应该是 application 与该类型是可读的还是可执行的无关。这是因为语言/类型本身有自定义字符集确定机制,而不仅仅是泛型字符集参数。 text 的子类型应该能够由代理转码到另一个字符集,从而更改charset参数。这不适用于JavaScript,因为:

The reason it is supposed to be application is not anything to do with whether the type is readable or executable. It's because there are custom charset-determination mechanisms laid down by the language/type itself, rather than just the generic charset parameter. A subtype of text should be capable of being transcoded by a proxy to another charset, changing the charset parameter. This is not true of JavaScript because:

a。 RFC说用户代理应该对脚本进行BOM嗅探以确定类型(我不确定是否有任何浏览器实际执行此操作);

a. the RFC says user-agents should be doing BOM-sniffing on the script to determine type (I'm not sure if any browsers actually do this though);

b。浏览器使用其他信息 - 包括页面的编码,在某些浏览器中使用脚本字符集属性 - 来确定字符集。因此,任何试图对资源进行转码的代理都会破坏其用户。 (当然,实际上没有人会使用转码代理,但这就是意图。)

b. browsers use other information—the including page's encoding and in some browsers the script charset attribute—to determine the charset. So any proxy that tried to transcode the resource would break its users. (Of course in reality no-one ever uses transcoding proxies anyway, but that was the intent.)

因此必须保留文件的确切字节 ,这使得它成为二进制应用程序类型,而不是技术上基于字符的文本

Therefore the exact bytes of the file must be preserved exactly, which makes it a binary application type and not technically character-based text.

出于同样的原因, application / xml 正式优先于 text / xml :XML有自己的带内字符集信令机制。每个人也忽略XML的应用程序

For the same reason, application/xml is officially preferred over text/xml: XML has its own in-band charset signalling mechanisms. And everyone ignores application for XML, too.

text / javascript text / xml 可能不是官方的正确的东西,但是出于兼容性原因,每个人今天使用的东西,以及它们不是正确的东西的原因实际上完全不重要。

text/javascript and text/xml may not be the official Right Thing, but there are what everyone uses today for compatibility reasons, and the reasons why they're not the right thing are practically speaking completely unimportant.

这篇关于Javascript MIME类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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