in reply to I know this code could be better...
What all of the responders missed: In your intro you say
"The $is_script thing skips printing a header if the file contains java".
I thought "Huh? Does he mean only the HTML- or the HTTP-Header too?".
After looking at your code I saw he means the HTTP-Header too.
So your program gives 500 Internal Server Error for all scriptfiles.