Both firefox and chrome are showing that javascript files from my server are served as MIME type text/html. The javascript files have a .js extension.

First, mime_module is installed and active:

apachectl -M | grep mime
 mime_magic_module (shared)
 mime_module (shared)
Syntax OK

Second, I have this in my conf file:

AddType text/css .css
AddType text/javascript .js

I tried adding this:

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

and restarted apache, but the javascript files still show as "text/html" in Chrome and Firefox. Nothing shows in error.log and access.log isn't returning anything useful: - - [03/Mar/2015:10:42:00 -0500] "GET /some/dir/js/app-min.js HTTP/1.1" 200 14642

Here are headers on one of the .js files (as seen in Firefox)

Connection: close
Content-Type: text/html; charset=UTF-8
Server: Apache
Strict-Transport-Security: max-age=63072000; includeSubDomains
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-Permitted-Cross-Domain-Policies: master-only
X-WebKit-CSP: default-src 'self'
X-XSS-Protection: 1; mode=block

This file shows as type html in Firefox inspector.

Here's the header of the same file as served by my laptop's apache instance:

Connection: Keep-Alive
Date: Tue, 03 Mar 2015 15:43:52 GMT
Keep-Alive: timeout=5, max=95
Server: Apache/2.4.7 (Ubuntu)

This file shows as type js in Firefox inspector. Note that the local instance of Apache (2.4) is not responding with Content-Type.

Why is the main server defying AddType? I've added this to both the httpd.conf and ssl.conf (though my site forces 443). I've restarted apache (no syntax errors).


I had a smilimar issue, some sysadmin add the next directive con conf.modules.d/10-php.conf:

SetHandler application/x-httpd-php

But this set all extencions to that hander, so I change it for:

AddHandler php5-script .php

Issue solved :)

| improve this answer | |
  • Helped solve a problem multiple programmers couldn't solve in 2 weeks! Thanks – tutak Jul 4 at 20:50

Problem solved. conf.d/php.conf contained these lines:

AddHandler php5-script .php .phtml .html .css .js
AddType text/html .php

I changed the first line to

AddHandler php5-script .php .phtml .html
AddType text/html .php

Then saved and restarted Apache. The js & css files now appear with the correct mime type in Firefox/Chrome.

As an aside I tried adding AddType text/javascript .js just below AddType text/html .php, but the files still showed as text/html in Inspector. I had to remove .css and .js from AddHandler for the correct mime type to be sent.

| improve this answer | |
  • this did not work for me – shorif2000 Jan 19 '18 at 10:45
  • What os, apache and php versions are you on. The selected solution worked fine for me. – a coder Jan 19 '18 at 14:31
  • amazon EC2, apache 2.4.6, php7 as php-fpm. see here serverfault.com/questions/892882/… – shorif2000 Jan 19 '18 at 14:41
  • This question deals with apache on CentOS (see question tags). So there are probably configuration differences between EC2 and CentOS, and that's why the selected answer isn't working for you. Unfortunately I don't have time to install and debug EC2 for you, sorry. – a coder Jan 19 '18 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.