1

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>
JoshuaDavid
  • 8,861
  • 8
  • 47
  • 55
  • Probably you may find some help information by the link: http://stackoverflow.com/questions/17643228/jquery-scripts-runs-very-slow or you can provide more jQuery codes to see what's going on here. – Dayton Wang Dec 16 '14 at 00:48
  • I don't think jQuery is the issue here - it works fine (eventually). This is a script loading "problem". HTML5 spec says `If neither attribute [i.e. async and defer] is present, then the script is fetched and executed immediately, before the user agent continues parsing the page.` But it's not happening here. There's some kind of chromium optimization going on that's interfering, and I'd like to know more about it. An answer [here](http://stackoverflow.com/questions/10681388/do-running-script-tags-block-other-script-tags-from-downloading) says browsers try to parallelize script downloads. – JoshuaDavid Dec 16 '14 at 07:21
  • 1
    Yes. I believe by default most browsers today will actually load the scripts in parallel; but the browser will not by default execute the scripts in parallel. Here are some references may help: https://bardevblog.wordpress.com/2013/01/03/browser-script-loading/ http://www.stevesouders.com/blog/2010/12/06/evolution-of-script-loading/ http://www.stevesouders.com/blog/2010/02/07/browser-script-loading-roundup/ – Dayton Wang Dec 16 '14 at 17:10

1 Answers1

2

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!

mmocny
  • 8,775
  • 7
  • 40
  • 50