applicationHost

Page B

The following content represents a basic overview of this page's script structure and [intended] execution flow. When a particular script is mentioned below, it is linked to the "debug" version, as a convenient reference, but the page actually uses the minified versions when available. For a better (more reliable?) explanation of this page's loading behavior, re-run the WebPagetest.org results.  ==>

1.  Load init-b.js

init-b.js is hard-coded in the page's <head> section. This is the only hard-coded <script> element in this document; the other scripts are dynamically appended to the <head>.


    <head>
        <meta charset="utf-8" />
        <title>Page B</title>
        <link type="text/css" rel="stylesheet" href="css/style.css" />
        <script type="text/javascript" src="js/init-b.js"></script>
    </head>

2.  Execute init-b.js

init-b.js has two main sections of code:

  1. an immediately-invoked function expression (IIFE), and
  2. a function definition for lazyFunction(), which is attached to the window.load event.

2.1.  Execute IIFE

Neither dependencies ( require.deps ) nor a callback function ( require.callback ) are defined in the require global object's configuration. It does, however, define a shim configuration for sammy.js.


    (function() {

        require = {

            // ...

            // callback: undefined

            // deps: undefined

            shim: {
                'sammy': {
                    deps: ['jquery'],
                    exports: 'Sammy'
                }
            }

        };

    }());

2.2.  Define lazyFunction() & Attach to window.load

require.js is dynamically loaded by lazyFunction() after the window.load event. The data-main attribute is set to main-b.js, which tells require.js to load it next (i.e., as soon as require.js is done loading).


    var lazyFunction = function() {
        var s = document.createElement('script');
        s.type = 'text/javascript';
        s.src = 'lib/require/require.js';
        s.setAttribute('data-main', 'app/main-b');
        document.getElementsByTagName('head')[0].appendChild(s);
    }

    window.onload = function() {
        lazyFunction();
    }

3.  Load & Execute require.js

4.  Load main-b.js and Begin App