Forum Moderators: open

Message Too Old, No Replies

JS header shows Content-Type: text/html

         

keyplyr

8:51 am on Dec 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



To speed up a couple very large JS, I'm considering serving them with PHP, which I already compress (gzip.) This is simple, no additional scripting required and tests fine with IE/8 and FF/3.5.6.

However, the response header for the JS displays "Content-Type: text/html" (I parse all HTML as PHP, settings in php.ini.) My cache-control is the same for JS as it is HTML, so in this respect all is well but I wondering about other problems.

Are there potential usability issues serving JS as "Content-Type: text/html" instead of "Content-Type: X-javascript?"

KenB

4:03 pm on Dec 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was seeing the same problem with my JS files. I tried defining the content-type in my .htaccess file, but this didn't seem to do anything. I finally gave up and used PHP to insert the proper content type header in my JS. It is not as processor efficient as using the .htaccess file, but it works.

keyplyr

8:29 pm on Dec 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



My PHP will send out the same header for everything, it's the way it set-up on the server; can't change it. So I either don't use PHP to compress JS (leaving them slow) and display the correct content-type - OR - compress them (reducing %68) but displaying the content-type as text/html. The question is, are there any significant ill affects doing the later?

g1smd

8:33 pm on Dec 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Have you tried adding an additional HEADER directive to your output, ahead of any content.

keyplyr

8:53 pm on Dec 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes g1smd, adding a HEADER directive to each JS file will correct the content-type. Thanks for the suggestion. I was trying to avoid this. I was hoping to get several opinions saying, "nah - you'll be fine!"

I have over 200 JS scripts in use and this kinda defeats my labor-economic attitude for the day :)

KenB

9:02 pm on Dec 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will probably be okay with your JS files being sent with the wrong content type, but it isn't ideal. Actually using PHP to fix the header also isn't ideal. You should be able to fix this via your .htaccess file (which for me doesn't work).