Jump to content

Dynamically-generated javascript files


calande

Recommended Posts

Hi guys,In this page about introduction to JS, it says you need to put a .js extension. I suggest adding that if the user want the external JS file to be dynamic (ie: on a multilingual site), he can use a different extention such as .php, etc...Thanks!:)
I think that might cause more confusion than what it's worth, presuming people study it in the order HTML->CSS->Javascript->Serverside programming. It would be getting ahead of oneself if the reader has no knowledge of (to use your example) PHP and thus the extension .php, and might make the reader try to call a javascript file with the extension .php without realizing what server-requirements are necessary to parse the file, even for javascript. That's why it's better to have info like that in the serverside language section, under the tutorials dealing with the particular language (PHP for instance) communicating with javascript and the user-agent.
Link to comment
Share on other sites

I agree that it's not the best idea to say that Javascript files need a .js extension. You can say that you can use any extension you want, but most people use .js, without getting into the details why. That way people won't be (as) confused when they look at someone's source and see this:<script type="text/javascript" src="script.php"></script>

Link to comment
Share on other sites

Saying "most people" sounds too "high school" like if you ask me, but I still agree with Jonas and justsomeguy.I think the best way it might be put will be to add a note at the bottom of the page saying something like:

Note: You could also use any other extension for external JavaScript files. There can be consequences of that change, to which we won't go into detail now, so for the time being, use ".js" as a file extension.
THAT sort of thing, or say nothing.If a person is advanced enough to know what PHP and other S3Ls are all about, (s)he'll be advanced enough to realize why would (s)he need to change the extensions of JavaScript files to the extension of the S3L of choise. And if they're really advanced, they'll know they could even dynamically generate ".js" files with S3Ls, by configuring the server to recognize the ".js" extension as the S3L's extension.
Link to comment
Share on other sites

Or maybe it could be said that "when naming files with javascript only, the convention is to use the extension .js".Either way, I think this (and similar topics regarding choice of vocabulary or formulation) would better be emailed to Hege for her/their consideration...mail_w3schools.gif

Link to comment
Share on other sites

Heck, it's even possible to treat a .js file as a PHP file with a .js extension :)
Of course that's even more complicated though, as it requires server settings access, such as .htaccess...
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...