views:

46

answers:

3

What is the correct syntax for adding an external reference to a JavaScript file (.js) within another JavaScript file?

+4  A: 

There isn't any.

You can add a <script> block to the document, but it will execute asynchronously.

SLaks
Assuming of course he's using JavaScript on a browser. ;-)
T.J. Crowder
@Michael: If you aren't (using JavaScript on a browser), you'll have to use whatever mechanisms exist in your environment that allow you to load code. There's bound to be something, even if (in the absolute worst case) it's loading the file as text and then eval'ing it.
T.J. Crowder
I was able to add a reference to the java script in some of the HTML code managed through the UI.
Michael Kniskern
A: 

Alternatively store all your .js files in a php file.

<script src="js.php" type="text/javascript"></script>

php:

<?php
require 'js/myjs1.js';
require 'js/myjs2.js';
?>
woodscreative
A: 

I suppose you could load content of file via ajax and use eval().

Rin