I dynamically load external js file with this function:
function getscript(url,callback) {
callback = (typeof callback != 'undefined') ? callback : {};
$.ajax({
type:"GET",
url:url,
success:callback,
dataType:"script",
cache:true
});
}
File I'm loading has variables in it, for me to load them and use them when needed. Some variables in external files are declared with var, some are continuation of already declared array.
On laptop/regular computer this works - I check if there is variable (from external js) already loaded/declared, and if there isn't I load external js with above function. When js is loaded, I continue to work with loaded variables.
But when I try it on smartphone (android), function returns success, but I can't work with/access variables from that external file - nothing happens. But if I refresh page, external file is cached and I can work with it.
Again, there is no problem on laptop/regular computer, but on smartphone I'm testing on.
Does this have something to do with android version I'm testing with, or is it something else?
Kind of solution:
When external file is loaded, check if one of the external variables is still undefined, and if it is, repeat the process that initiated external load again, but this time file will be loaded. It works.