JavaScript 文件的适当内容类型标头是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3987384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is an appropriate content-type header for JavaScript files?
提问by Umair Jabbar
I am delivering a JS response from a PHP file. When setting the Content-Type
header which value should I use, application/javascript
or text/javascript
?
我正在从 PHP 文件提供 JS 响应。设置Content-Type
标题时我应该使用哪个值,application/javascript
还是text/javascript
?
What's the difference between the two?
两者有什么区别?
回答by You
According to the IANA Registered MIME media type list, JS has two registered MIME types; the obsolete text/javascript
and the now official application/javascript
.
根据IANA 注册的 MIME 媒体类型列表,JS 有两种注册的 MIME 类型;过时的text/javascript
和现在正式的application/javascript
。
Thus, use application/javascript
.
因此,使用application/javascript
.
回答by Gordon
From Wikipedia on Internet Media Types
来自Wikipedia on Internet Media Types
application/javascript:
JavaScript; Defined in RFC 4329but not accepted in IE 8 or earlier
application/javascript:
JavaScript; 在RFC 4329 中定义但在 IE 8 或更早版本中不被接受
There is also the deprecated text/javascript
(which IE will probably not choke on).
还有不推荐使用的text/javascript
(IE 可能不会窒息)。