How To Import Multiple JavaScript Files

Including a javascript file in another javascript file is common in web development. Because many times we include the javascript file at run time on the behalf of some conditions.

How to Include a JavaScript file in another JavaScript file?

So, we can achieve this using javascript as well as using jQuery.

Method 1: Use JavaScript to include another JavaScript file

Step 1: Add following function in web page.
<script type='text/javascript'>
function loadScript(url){var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
script.async = true;
script.defer = false;

Step 2: Just call the below loadScript function, Where you want to include the js file.
<script type='text/javascript'>

Method 2: Use jQuery to include another JavaScript file.

Step 1: Add jQuery File in your webpage.
<script src=""/>
Don't add this if you are already using any jQuery.js file
Step 2: Just call the  getScript  function functions.

Tags:- how to use multiple javascript files, multiple <script> tags in <head>, javascript multiple src, adding more than one javascript to a page, javascript multiple files best practices, html include all javascript files in folder, javascript import all files in directory, combine multiple javascript files into one, Speed Up Your Javascript Load Time, How do you import multiple javascript files in HTML index file without the bloat, How do I include a JavaScript file in another JavaScript file, javascript include html file, javascript call function from another js file, javascript include external js, include all js in one file, include js file in another js file jquery, javascript include js file in html, js import from another file
Share it:



How To







Post A Comment: