将我的JS MIME类型设置为“text / javascript”

时间:2021-03-09 21:22:37

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”服务。当我检查浏览器和localhost(或我的服务器)之间的网络通信时,我的Web服务器上托管的JS的MIME类型是application / x-javascript。来自Google CDN的JS(例如jQuery)是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?

建议?

2 个解决方案

#1


9  

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

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

#2


2  

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,您应该看到更改

#1


9  

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

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

#2


2  

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,您应该看到更改