将我的JS MIME类型设置为“text / javascript”; [英] Set my JS MIME type to "text/javascript"

查看:714
本文介绍了将我的JS MIME类型设置为“text / javascript”;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据这个: Javascript MIME类型,似乎我应该为我的JS服务文/ JavaScript的。当我检查浏览器和localhost(或我的服务器)之间的网络通信时,我的Web服务器上托管的JS的MIME类型是application / x-javascript。来自Google CDN的JS(例如jQuery)是text / javascript。

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.

我想让我的JS成为text / javascript。在我的.htaccess中,我尝试添加: AddType text / javascript .js ,但它没有改变我的MIME类型。

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.

建议?

推荐答案

AddType 指令应该是足够的,除非有强迫类型的东西,但你也可以尝试:

The AddType directive should be sufficient enough unless there's something that's forcing the type, but you can also try:

<Files "*.js">
    ForceType text/javascript
</Files>

更好的解决方案可能是查看vhost / server配置和所有apache配置文件(对于 application / x-javascript 的实例,可以默认包含在您的配置中,以查看其设置方式。最好在那里更改它而不是htaccess文件,它可能没有必要的覆盖选项(mod_mime的 AddType ForceType 需要 FileInfo AllowOverride 选项。

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 FileInfo AllowOverride option).

这篇关于将我的JS MIME类型设置为“text / javascript”;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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