Is there a certain place that java scripts need to be located? I noticed that in the config file it indicates that for cgi scripts you need a 'shebang line' at the top of each script. Do java scripts need a similar indicator to tell it what program to use?
Client-side Javascript is really only plain text, as far as Apache is concerned. It just passes any .js file right to the browser, without any intervention, just like a regular HTML or text page. You should definitely not try to treat plain Javscript as a CGI, since that would make the server try to parse the javascript file, instead of just sending it to the browser.
It is possible to interfere with Apache's default handling of .js files, if you change the javascript setting in your "conf/mime.types" file, or if you try something like "AddType application/x-javascript", or some other such silliness in your httpd.conf file. Resist that temptation, please.
Javascript was originally conceived as both a client-side and a server-side language, and it is possible to still do server-side Javascript in a couple of webservers, but Apache has no server-side handling for Javascript, so any attempt to set special server parsing for Javascript would just cause errors.
On the other hand, you CAN set any kind of file as the SRC attribute of a script tag, so you can actually have javascript output be delivered by a CGI file. That is a different story, though. In that case, there is server-side CGI code, such as Perl, which then outputs valid Javascript to the browser, just as it outputs HTML normally. SOmething like:
Let me stress THIS IS NOT SERVER_SIDE PARSING OF JAVASCRIPT; it is server-side parsing of CGI, which delivers text in the form of javascript to the browser. To the browser, Javascript is just plain text, and it doesn't care where it gets it from.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.