Forum Moderators: phranque

Message Too Old, No Replies

AddHandler + AddType troubles

AddType being ignored

         

wiglaf

7:45 pm on Feb 15, 2008 (gmt 0)

10+ Year Member



I wanted to stick some php into my .js files to make them dynamic, but I want it to be transparent to users (ie. not having a .php extension), so I put in htaccess:

AddHandler application/x-httpd-php .js

It works. The only problem is that when a user tries to view the .js file, it gets served up as application/x-httpd-php and the browser renders it as such (ignoring whitespace and such). So I add a line of php in the .js file:

header("content-type:application/x-javascript");

It works. But I don't want to have to add this line in all my current (and future) .js files that won't be using any php. So I add another directive:

AddType application/x-javascript .js

It doesn't work. I went so far as to put an htaccess file in my js directory with the following:

ForceType application/x-javascript

Still any .js file that doesn't have it's content-type explicitly set with a call to php's header() gets served as x-httpd-php. This is not strictly a big deal since the javascript still functions normally, but it'd be nice to have it render like normal in browsers. Is there any way to do that? Thanks.

jdMorgan

2:00 am on Feb 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just wondering, have you tried the standard JavaScript MIME-type?

AddType text/javascript .js

Jim

wiglaf

2:18 am on Feb 16, 2008 (gmt 0)

10+ Year Member



I had not tried that, but that doesn't work either.