...

View Full Version : JavaScript include using .php file (not .js)



crazy horse
09-21-2003, 05:49 PM
Hello. I am currently experimenting with using PHP to generate a JavaScript array within a source file:

<script language=JavaScript src=includes/preload.php></script>

This works in all the browsers I've tested and treats the .php file like a .js file. Does anyone know of any browsers that can't do this?

crazy horse
09-21-2003, 05:55 PM
Oops - posted this in the wrong section. Sorry.

beetle
09-21-2003, 07:25 PM
As long as you send the correct MIME-type

header( "Content-type: text/javascript" );You'll be okay.

liorean
09-21-2003, 07:50 PM
Actually, the 'text/javascript' content type is wrong. The right one is 'application/x-javascript', and all JavaScript enabled browsers accept it in the Content-Type header, even though some doesn't accept it in the type attribute of the script element.

beetle
09-21-2003, 08:36 PM
Very true - I too often forget that. Thanks for the correction, liorean :thumbsup:

joh6nn
09-21-2003, 11:26 PM
when did the mime-type change, and why? anyone got a link that explains?

crazy horse
09-22-2003, 01:09 AM
Cheers guys. This works great. :thumbsup:

liorean
09-22-2003, 08:42 AM
Joh6nn - it never changed. 'text/javascript' never got registred (haven't even been suggested for registration at the IETF) and the 'application/x-<insert language, program or document format here>' is the default content type for new formats. Thus, 'application/x-javascript' is and always was the right content type for JavaScript, something as I mentioned all browsers accept in the Content Type header but not in the type attribute for some strange reason.

Inigoesdr
06-10-2008, 08:17 AM
Oh, good thing you clarified in this nearly 5 year old thread.

malfist
06-10-2008, 02:21 PM
lol, and on his first post too!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum