12

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?

Community
  • 1
  • 1
StackOverflowNewbie
  • 39,403
  • 111
  • 277
  • 441
  • 4
    It should be `application/javascript`. No browser cares if it is `application/x-javascript` though. The best way to fix that would be to upgrade the underlying system, which has an out of date mime.types file. – Quentin Oct 17 '12 at 13:19
  • "No browser" or "no CURRENT browser?" Seems from the link that IE might have an issue. And though it seems the `application/javascript` is the "proper" MIME type, I'm trying to do as Google and use `text/javascript`. – StackOverflowNewbie Oct 17 '12 at 13:31
  • `application/x-javascript` appears on both my WAMP and LAMP system. I'm thinking that somehow my code, .htaccess, etc. is the culprit. – StackOverflowNewbie Oct 17 '12 at 13:33
  • I'm not really sure why you'd need or want to change this, do you have to support ancient browsers? – WebChemist Oct 26 '12 at 10:52

2 Answers2

12

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

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
3

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

WebChemist
  • 4,393
  • 6
  • 28
  • 37