---
title: "Can I dyamically load multiple scripts by order"  
description: "Can I dyamically load multiple scripts by order"  
author: "Manoj Bhatt"  
published: 2015-02-01  
updated: 2015-02-01  
canonical: https://www.mindstick.com/forum/12927/can-i-dyamically-load-multiple-scripts-by-order  
category: "javascript"  
tags: ["jquery"]  
reading_time: 1 minute  

---

# Can I dyamically load multiple scripts by order

I'm [lazy loading](https://www.mindstick.com/articles/324873/lazy-loading-in-entity-framework) various scripts depending on what [page](https://www.mindstick.com/articles/13031/why-to-make-a-wikipedia-page) I'm on. Up [till now](https://answers.mindstick.com/qa/40087/which-is-the-best-indian-tv-serial-till-now), I've only loaded one per page. Now that I'm [starting](https://www.mindstick.com/blog/12024/things-you-need-to-know-when-starting-your-own-business) to [clean up](https://www.mindstick.com/interview/34124/how-can-you-clean-up-temporary-files-that-are-older-than-a-specific-date) and reduce the number of scripts, I have to lazy [load](https://answers.mindstick.com/qa/33737/what-is-meant-by-average-load-time) two scripts (or more) scripts for the same page. One [script](https://www.mindstick.com/interview/477/how-can-i-execute-a-php-script-using-command-line) is dependent of the other so I need to load these in correct order.

What is the best way to achieve this?

**My [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):**

```
// Plupload must load before imageHandling.jsjQuery(document).ready(function() {    //Conditional load    load_script('.image-drop-box','vendor/plupload/plupload.full.min.js');    load_script('.image-drop-box','imageHandling.js'); });  // Script loader// .exists() is a custom func that checks if an element exists on pagefunction load_script(element, js) {    $(element).exists(function(){        var script = document.createElement('script');        var footer = document.getElementById('footer');        script.type = 'text/javascript';        script.src = '/js/'+ js;        footer.appendChild(script);    });}
```

## Replies

### Reply by marcel ethan

If you're not stepping out of the same domain, you could use getScript()

```
var scriptUrls = ["http://x/foo", "http://x/bar"];var loadScr;loadScr = function(){    if(scriptUrls.length==0)return;    var currentUrl =
scriptUrls.pop();    $.getScript(url,
loadScr);}loadScr();
```


---

Original Source: https://www.mindstick.com/forum/12927/can-i-dyamically-load-multiple-scripts-by-order

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
