Mobile Chrome Apps and handling of JS refs

74 views Asked by At

New at Chrome Apps. Using cca and CADT for mobile development.

In the following code, why is jQuery not immediately available? Is there some async magic being auto-applied?

I don't have this behavior in a vanilla cordova project.

<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script type="text/javascript">

    setTimeout(function()
    {
        console.log($);    // $ is jQuery
    }, 1000);

    console.log($);        // $ is undefined

</script>
1

There are 1 answers

0
mmocny On BEST ANSWER

Our current bootstrap code will not load the html of your chrome app windows in a way you typically expect from a browser. The reasons are long, but the short story is that we have to bootstrap to set up the environment, then inject the content around the bootstrap.

One of the consequences is that scripts do not block dom content loading. I guess another consequence is that inline script execution is not delayed until preceding scripts have loaded.

We may be able to fix this bug, I'll take a look. I've filed: https://github.com/MobileChromeApps/mobile-chrome-apps/issues/482

Thanks for reporting the issue!