javascript - 为什么新标准是 `application/javascript` 而不是 `text/javascript` ?

标签 javascript mime-types

<分区>

Possible Duplicate:
Javascript MIME Type

我注意到 MIME 类型 text/javascript 已被弃用,取而代之的是 application/javascriptWikipedia seems to confirm this .然而,Javascript 以源代码形式分发,即文本。 application 一词对我来说听起来像是编译后的二进制文件。事实上,现代 Javascript 解释器确实对源文本执行 JIT 编译,从而生成一个应用程序,这意味着源文本本身并不是一个应用程序。那么为什么首选使用 application/javascript MIME 类型呢?

最佳答案

根据 RFC 2045 :

In general, the top-level media type is used to declare the general type of data, while the subtype specifies a specific format for that type of data. Thus, a media type of "image/xyz" is enough to tell a user agent that the data is an image, even if the user agent has no knowledge of the specific image format "xyz". Such information can be used, for example, to decide whether or not to show a user the raw data from an unrecognized subtype -- such an action might be reasonable for unrecognized subtypes of text, but not for unrecognized subtypes of image or audio. For this reason, registered subtypes of text, image, audio, and video should not contain embedded information that is really of a different type. Such compound formats should be represented using the "multipart" or "application" types.

编辑

因此,虽然 JavaScript 确实是文本,但它也是“包含真正不同类型的嵌入信息的文本的注册子类型”,因此需要 application 定义的顶级媒体类型那个 RFC。

有许多 application/... MIME 类型不是“应用程序”(可执行二进制文件或代码),例如:application/zip(用于 Zip 存档) .因此,从这个意义上说,application 顶级媒体类型的命名颇具误导性。

关于javascript - 为什么新标准是 `application/javascript` 而不是 `text/javascript` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13591069/

相关文章:

javascript - 记录与 socket.io 的连接和断开连接

javascript - 为什么 Node js + React 中请求正文为空?

javascript - 将 MSAL 与 React 结合使用,acquireTokenSilent 导致应用刷新并失败

php - 如何返回图像

python - HTML URL生成下载时如何了解PDF的内容类型

javascript - 无法解码 Firefox 媒体资源

javascript - Angular 2 中组件/视觉继承的最佳方法?

javascript - 按照路线在谷歌地图上画线

java - java中的多部分文件上传检查mime类型

java - 参数中的 NdefRecord.createMime 错误