1

Will the JavaScript execution till an external script loads in this condition?

<script type="text/javascript" src="external/ext.js"></script>
<script type"text/javascript">var same_variable = 1;</script>

What happens if ext.js also has the same variable used?

I'm troubleshooting any issue in my ASP.NET application where jQuery is loaded multiple times and the plugins are being overwritten. I'm having few user controls which are loaded in the pages with some jQuery plugin behavior. The jQuery reference is given in master page. But some third party products are installed in the application too which are loading their own jQuery. Where exactly should I put the noConflict() method? In master page immediately after I load jQuery or can I put it in my user control before I call the plugin method?

More details -

In Master Page I've the following references in the same order-

<jquery.min.js>
<plugin1.js>
<plugin2.js>
<plugin3.js>

In my user control (ascx file)

<plugin4.js>
<script> 
  //Use plugin4 
  //ERROR
</script>

A third party product is loading its own jQuery.

Observation using Chrome Network Tab -

The JS files are loaded in the following order -

<jquery.min.js>
<plugin1.js>
<plugin2.js>
<plugin3.js>
<plugin4.js>
<third party jquery.js>

Hence when I use plugin4 inside my user control it is giving an error that "Object has no method".

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
NLV
  • 21,141
  • 40
  • 118
  • 183
  • _"where jQuery is loaded multiple times"_ Well there's your problem. Install those 3rd party libraries without jQuery. – Cerbrus May 12 '14 at 14:16
  • It is not under my control. Those are enterprise products used across the organization. – NLV May 12 '14 at 14:16
  • I did a quick sample and the execution is indeed waiting for the external jS to load and continuing the execution. Is this observation correct? – NLV May 12 '14 at 14:17
  • @NLV - Javascript is asynchronous, race condition is not the appropriate term here. Whatever will load and run first will load and run first it's that nature of javascript. Seeing some more of your headers will assist in troubleshooting. Also, if JQuery is being loaded externally, why load it yourself instead of just writing extensions and leveraging the already loaded JQuery? – tremor May 12 '14 at 14:21
  • Have added more details. Kindly check. – NLV May 12 '14 at 14:27
  • 1
    http://stackoverflow.com/a/21736074/3300831 – martynas May 12 '14 at 14:27
  • @martynas should the noConflict statement come after plugin references in my case? – NLV May 12 '14 at 14:31
  • 1
    When I needed to run multipule versions of jQuery (also had no choice) I found this link quite helpful. http://conceptf1.blogspot.com/2013/12/conflict-in-multiple-jquery-files-on-same-page.html – Damon May 12 '14 at 15:45
  • @dragonslovetacos Thank you. It gave some clarity for my issues. – NLV May 13 '14 at 07:50

0 Answers0