title: Marionette js itemview not defined: then on browser refresh it is defined and all works well - race condition?
body: <p>Yeah it's just the initial browser load or two after a cache clear.  Subsequent refreshes clear the problem up.</p>
  
  <p>I'm thinking the item views just aren't fully constructed in time to be used in the collection views on the first load.  But then they are on a refresh?  Don't know.</p>
  
  <p>There must be something about the code sequence or loading or the load time itself.  Not sure.  I'm loading via require.js.  </p>
  
  <p>Have two collections - users and messages.  Each renders in its own collection view.  Each works, just not the first time or two the browser loads.</p>
  
  <p>The first time you load after clearing browser cache the console reports, for instance:</p>
  
  <p>"Uncaught ReferenceError: MessageItemView is not defined" </p>
  
  <p>A simple browser refresh clears it up.  Same goes for the user collection.  It's collection view says it doesn't know anything about its item view.  But a simple browser refresh and all is well.  </p>
  
  <p>My views (item and collection) are in separate files.  Is that the problem?  For instance, here is my message collection view in its own file:</p>
  
  <p><strong>messagelistview.js</strong></p>
  
  <pre><code>    var MessageListView = Marionette.CollectionView.extend({
          itemView: MessageItemView,
          el: $("#messages")
      });
  </code></pre>
  
  <p>And the message item view is in a separate file:</p>
  
  <p><strong>messageview.js</strong></p>
  
  <pre><code>    var MessageItemView = Marionette.ItemView.extend({
          tagName: "div",    
          template: Handlebars.compile(
                  '&lt;div&gt;{{fromUserName}}:&lt;/div&gt;' +
                '&lt;div&gt;{{message}}&lt;/div&gt;' +
          )
      });
  </code></pre>
  
  <p>Then in my main module file, which references each of those files, the collection view is constructed and displayed:</p>
  
  <p><strong>main.js</strong></p>
  
  <pre><code>    //Define a model
      MessageModel = Backbone.Model.extend();
  
      //Make an instance of MessageItemView - code in separate file, messagelistview.js
      MessageView = new MessageItemView();
  
  
      //Define a message collection 
      var MessageCollection = Backbone.Collection.extend({
          model: MessageModel    
      });
  
      //Make an instance of MessageCollection
      var collMessages = new MessageCollection(); 
  
  
      //Make an instance of a MessageListView -  code in separate file, messagelistview.js
      var messageListView = new MessageListView({
          collection: collMessages
      });
  
      App.messageListRegion.show(messageListView);
  </code></pre>
  
  <p>Do I just have things sequenced wrong?  I'm thinking it's some kind of race condition only because over 3G to an iPad the item views are always undefined.  They never seem to get constructed in time.  PC on a hard wired connection does see success after a browser refresh or two.  It's either the load times or the difference in browsers maybe?  Chrome IE and Firefox on a PC all seem to exhibit the success on refresh behavior.  Safari on iPad fails always.</p>
  
  <p><strong>PER COMMENT BELOW, HERE IS MY REQIRE BLOCK:
  in file application.js</strong></p>
  
  <pre><code>    require.config({
          paths: {
              jquery: '../../jquery-1.10.1.min',
              'jqueryui': '../../jquery-ui-1.10.3.min',
              'jqueryuilayout': '../../jquery.layout.min-1.30.79',
              underscore: '../../underscore',
              backbone: '../../backbone',
              marionette: '../../backbone.marionette',
              handlebars: '../../handlebars',
              "signalr": "../../jquery.signalR-1.1.3",
              "signalr.hubs": "/xyvidpro/signalr/hubs?",        
              "debug": '../../debug',
              "themeswitchertool": '../../themeswitchertool'
          },
  
          shim: {
              'jqueryui': {
                  deps: ['jquery']
              },
  
              'jqueryuilayout': {
                  deps: ['jquery', 'jqueryui']
              },
  
              underscore: {
                  exports: '_'
              },
  
              backbone: {
                  deps: ["underscore", "jquery"],
                  exports: "Backbone"
              },
  
              marionette: {
                  deps: ["backbone"],
                  exports: "Marionette"
              },        
  
              "signalr": {
                  deps: ["jquery"],
                  exports: "SignalR"
              },
  
              "signalr.hubs": {
                  deps: ["signalr"],
                  exports: "SignalRHubs"
              },
  
              "debug": {
                  deps: ["jquery"]
              },
  
              "themeswitchertool": {
                  deps: ["jquery"]
              }
          }
      });
  
  
      require(["marionette", "jqueryui", "jqueryuilayout", "handlebars", "signalr.hubs", "debug", "themeswitchertool"], function (Marionette) {
          window.App = new Marionette.Application();
  
          //...more code
  
      })
  </code></pre>
  
  <p>Finally, inside the module that uses creates the collection views in question, the list of external file dependencies is as follows:</p>
  
  <pre><code>    var dependencies = [
          "modules/chat/views/userview",
          "modules/chat/views/userlistview",
          "modules/chat/views/messageview",
          "modules/chat/views/messagelistview"
      ];
  </code></pre>
  
  <p>Clearly the itemViews are listed before collectionViews.  This seems correct to me.  Not sure what accounts for the collectionViews needing itemViews before they are defined.  And why is all ok after a browser refresh?</p>