[thelist] JavaScript included file question

Kelly Hallman khallman at wrack.org
Thu Aug 28 12:34:26 CDT 2003


On Thu, 28 Aug 2003, Nan Harbison wrote:
> <script language="JavaScript"
> src="<?=(($incJavaScript)?$incJavaScript:STR_GLOBAL_JAVASCRIPT)?>">
> </script>
> 
> There is another file on this site that has the statement:
> $incJavaScript = STR_GLOBAL_JAVASCRIPT;
> 
> and a global setting page has this:
> define("STR_GLOBAL_JAVASCRIPT", WS_PATH.'include/global_javascript.js');
> 
> Can someone tell me what the point of this is? It seems like a rather
> round-about way to call an included file.

On the surface, it is a bit of overkill. Setting $incJavaScript =
STR_GLOBAL_JAVASCRIPT seems to be pointless, considering that is also the
default by virtue of how the script src= is set up. However, if you
omitted that assignment it would behave the same (so you don't need to
remember to include the global_javascript.js file each time). The main
advantage is that default is automatic, but you could set $incJavaScript
to a different filename on a per-script basis to override that default.

This isn't the most flexible approach, but it does have use if you only 
need to include one javascript file at most per page.

-- 
Kelly Hallman
http://wrack.org/




More information about the thelist mailing list