StackOverflowNewbie
StackOverflowNewbie

Reputation: 40653

Set my JS MIME type to "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.

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.

Suggestions?

Upvotes: 14

Views: 20234

Answers (2)

Jon Lin
Jon Lin

Reputation: 143906

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>

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).

Upvotes: 12

WebChemist
WebChemist

Reputation: 4411

you need to change your settings in mimes.types file found in your apache conf folder. Change

application/javascript          js

to

text/javascript                 js

and restart apache, you should see the change

Upvotes: 4

Related Questions