Hi!
How to include one javascript file in other javascript file , like in PHP we use following code to include other files.
Thanks in advancePHP Code:include_once "filename.php";
| SitePoint Sponsor |


Hi!
How to include one javascript file in other javascript file , like in PHP we use following code to include other files.
Thanks in advancePHP Code:include_once "filename.php";

You don't have to. If you just put them both in the HTML they will have access to each other:
So for example if you call the function "doSomething" in file2.js and doSomething is declared in file1.js, it will work. The only thing is that you have to be careful what order you put the <script> tags in.HTML Code:<script type="text/javascript" src="file1.js"></script> <script type="text/javascript" src="file2.js"></script>





You can also dynamically create a reference to a script file inside another script file by creating a SCRIPT node, setting its type and src, and appending it to the document HEAD.


If I include javascript as follows
<script type="text/javascript" src="file1.js"></script>
Will it increase the size of html document?

No, it will decrease the size of the HTML document, compared to putting the JS directly into the <script> tags. But the browser still has to download "file1.js". The advantage is that the browser can then cache this file, instead of downloading it every time like it would if you had embedded javascript in the <head>.
Bookmarks