将我的 JS MIME 类型设置为“text/javascript”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12935119/
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
Set my JS MIME type to "text/javascript"
提问by StackOverflowNewbie
According to this: Javascript MIME Type, it seems that I should be serving my JS as "text/javascript". When I inspect the network communication between my browser and localhost (or my server), the MIME type of the JS that are hosted on my web server is application/x-javascript. The JS from Google CDN (e.g. jQuery) is text/javascript.
根据这个:Javascript MIME Type,看来我应该将我的 JS 服务为“text/javascript”。当我检查浏览器和本地主机(或我的服务器)之间的网络通信时,托管在我的 Web 服务器上的 JS 的 MIME 类型是 application/x-javascript。来自 Google CDN(例如 jQuery)的 JS 是 text/javascript。
I want to make my JS become text/javascript. In my .htaccess, I tried adding this: AddType text/javascript .js
, but it didn't change my MIME type.
我想让我的 JS 变成 text/javascript。在我的 .htaccess 中,我尝试添加这个: AddType text/javascript .js
,但它没有改变我的 MIME 类型。
Suggestions?
建议?
回答by Jon Lin
The AddType
directive should be sufficient enough unless there's something that's forcing the type, but you can also try:
该AddType
指令应该足够了,除非有强制类型的东西,但您也可以尝试:
<Files "*.js">
ForceType text/javascript
</Files>
A better solution may be to look through your vhost/server config and all of the apache config files (that may be included by default in your config) for instances of application/x-javascript
to see how that's being set. It may be better to just change it there instead of htaccess file, which may not have the neccessary override options (mod_mime's AddType
and ForceType
, for example, require the FileInfoAllowOverride
option).
更好的解决方案可能是查看您的 vhost/server 配置和所有 apache 配置文件(默认情况下可能包含在您的配置中)application/x-javascript
以查看其设置的实例。最好在那里更改它而不是 htaccess 文件,后者可能没有必要的覆盖选项(例如,mod_mimeAddType
和ForceType
,需要FileInfoAllowOverride
选项)。
回答by WebChemist
you need to change your settings in mimes.types file found in your apache conf folder. Change
您需要更改 apache conf 文件夹中的 mimes.types 文件中的设置。改变
application/javascript js
to
到
text/javascript js
and restart apache, you should see the change
并重新启动 apache,您应该会看到更改