How to correctly load dependent JavaScript files

Posted by Vaibhav Garg on Stack Overflow See other posts from Stack Overflow or by Vaibhav Garg
Published on 2010-05-15T14:53:30Z Indexed on 2010/05/15 17:54 UTC
Read the original article Hit count: 274

I am trying to extent a website page that displays google maps with the LabeledMarker. Google Maps API defines a class called GMarker which is extended by the LabeledMarker.

The problem is, I cant seem to load the LabeledMarker script properly, i.e. after the Google API loads and I get the 'GMarker not defined' error.

What is the correct way to specify the scripts in such cases?

I am using ASP.NET's ClientScript.RegisterClientScriptInclude() first for the google API url and then immediately after with the LabeledMarker script file.

The initial google API loader writes further script links that load the actual GMarker class. Shouldnt all those scripts be executed before the next script block(LabeledMarker script) is processed.

I have checked the generated HTML and the script blocks are emitted in the right order.

<script src="google api url" type="text/javascript"></script>
...
(the above scripts uses document.write() etc to append further script blocks/sources)
...
<script src="Scripts/LabeledMarker.js" type="text/javascript"></script>

Once again, the LabeledMarker.js seems to get executed before the google API finishes loading.

© Stack Overflow or respective owner

Related posts about google-maps

Related posts about JavaScript