14

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?

4
  • 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. Commented Oct 17, 2012 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. Commented Oct 17, 2012 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. Commented Oct 17, 2012 at 13:33
  • I'm not really sure why you'd need or want to change this, do you have to support ancient browsers? Commented Oct 26, 2012 at 10:52

2 Answers 2

12
+25

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

Sign up to request clarification or add additional context in comments.

Comments

4

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.