I would, instead, expose a method on your module to set the save method URL and in turn call that method, instead of setting a global variable.
<script type="text/javascript">
window.onModuleLoaded = function(module)
{
module.setSaveMethodURL('<?php echo $this->getUrl("page/save") ?>');
}
</script>
Then, in your module code you'd make a modification similar to the following: (depending on the design pattern you're using to expose your module)
module = (function ($) {
var url = saveMethodUrl;
var setSaveMethodURL = function(save_url)
{
url = save_url;
return url;
}
var returnObject = {
setSaveMethodURL: setSaveMethodURL
};
//this is executed when the module is loaded via the <script> tag)
//check to see if the moduleLoaded callback is defined
if (typeof window.onModuleLoaded != undefined)
{
//if the moduleLoaded callback is defined and is a function, call it
if (typeof window.onModuleLoaded == 'function')
{
window.onModuleLoaded(returnObject);
}
//if it's defined and is an object, iterate through the object and call
//each function in the object. (this allows you to add multiple callbacks
//to be executed when this module is loaded
else if (typeof window.onModuleLoaded == 'object')
{
for (key in window.onModuleLoaded)
{
if (typeof window.onModuleLoaded[ key ] == 'function')
{
window.onModuleLoaded[ key ](returnObject);
}
}
}
}
//return a reference to your setSaveMethodURL api method
return returnObject;
})();
As far as loading your module asynchronously, you can check out this other stack overflow question about loading javascript asynchronously