title: Require.js not working in Phonegap app when data-main attribute omitted
body: <p>Im developing a Phonegap app with Require.js. In my index.html, I had:</p>
  
  <pre><code>&lt;script type="text/javascript" src="cordova.js"&gt;&lt;/script&gt; 
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;script type="text/javascript" src="js/app/index.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
          app.initialize();  
  &lt;/script&gt;
  </code></pre>
  
  <p>The index.js file cannot be part of a Require module, a problem i detailed <a href="https://stackoverflow.com/questions/21289443/require-js-with-phonegap-and-push-notification-for-ios">here</a>. I wanted app.initialize() to execute after Require.js has set up all the config stuff. I used the solution <a href="https://stackoverflow.com/a/21314703/1716672">here</a>. So it becomes: </p>
  
  <pre><code>&lt;script type="text/javascript" src="cordova.js"&gt;&lt;/script&gt; 
  
  &lt;script src="js/require.js"&gt;&lt;/script&gt;
  &lt;script src="js/require-config.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      require(["app"]);
  &lt;/script&gt;
  
  &lt;script type="text/javascript" src="js/app/index.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt; 
          app.initialize();
  &lt;/script&gt;
  </code></pre>
  
  <p>So "data-main" is omitted meaning the the Require stuff runs immediately. This works perfectly in the browser. But for some reason when run as a Phonegap app, it generates Require script errors:</p>
  
  <pre><code>Uncaught Error: Script error for: app
  </code></pre>
  
  <p>It seems Require will not run when omitting "data-main" in a Phonegap app. Is this true?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The index.js file is:</p>
  
  <pre><code>var app = {
  // Application Constructor
  initialize: function() {
  
      this.bindEvents();
  
  },
  
  // Bind Event Listeners
  
  bindEvents: function() {
  
      document.addEventListener('deviceready', this.onDeviceReady, false);
  },
  
  
  /*
   * This function registers the device with the server, and stores the device id and the api key.
   * This should only ever execute once. 
   */
  registerDeviceWithServer: function(reg_id){
  
          var url = "http://push.theserver.ie/device_api/device";
          //var url = "http://localhost/theserver/device_api/device";
  
          $.ajax({
              url: url,
              type: "post",
              data: {project_title: 'mountmercy', platform: window.device.platform},
              pure_ajax: true,
              headers :{device_id:"63843",
              api_key:"hv7Vgd4jsbb"},
              success: function(data){
                  //alert("success in registerDeviceWithServer and id is");
  
                  var obj = jQuery.parseJSON(data);
  
                  var device_id = obj.id;
                  var api_key = obj.api_key;
                  window.localStorage.setItem('mountmercy_device_id', device_id);
                  window.localStorage.setItem('mountmercy_api_key', api_key);
  
                  //now update the Reg Id
                  app.updateRegId(device_id, api_key, reg_id);
              },
              error:   function(model, xhr, options){
                  //alert('failed in registerDeviceWithServer');
                  // alert('in Error');
                  console.log('response is : ');
                  console.log(app.logObject(xhr));
              },
          });
  },
  
  
  updateRegId: function(device_id, api_key, reg_id){
  
          var url = "http://push.theserver.ie/device_api/device/"+device_id;
  
          console.log('in updateRegId');
          console.log('updatig with reg_id of ');
          console.log(reg_id);
          $.ajax({
              url: url,
              type: "put",
              data: {reg_id: reg_id},
              pure_ajax: true,
              headers :{device_id:device_id,
              api_key:api_key},
              success: function(data){
                  //alert("success in updateRegId");
  
              },
              error:   function(model, xhr, options){
                  //alert('failed in updateRegId');
                  // alert('in Error');
                  console.log('response is : ');
                  console.log(app.logObject(xhr));
              },
          });
  
          console.log('after the update ajax');
  },
  
  
  // deviceready Event Handler
  //
  // The scope of 'this' is the event. In order to call the 'receivedEvent'
  // function, we must explicity call 'app.receivedEvent(...);'
  onDeviceReady: function() {
  
      console.log('in onDeviceReady and platform is ');
      console.log(window.device.platform);
      var pushNotification = window.plugins.pushNotification;
      if (window.device.platform == 'android' || window.device.platform == 'Android') {
          pushNotification.register(app.successHandler, app.errorHandler,{"senderID":"475226855592","ecb":"app.onNotificationGCM"});                        
      }
      else{
          //so its apple
           pushNotification.register(app.tokenHandler,app.errorHandler,{"badge":"true","sound":"true","alert":"true","ecb":"app.onNotificationAPN"});
      }
  
  },
  
  
  // result contains any message sent from the plugin call
  successHandler: function(result) {
     //alert('Callback Success! Result = '+result)
  },
  errorHandler:function(error) { 
      //alert('in errorHandler');
      //alert(error);
  },
  
  /*
   * 
   * For iOS
   */        
  tokenHandler:function(status) {
  
  
      var device_id = window.localStorage.getItem('mountmercy_device_id');
      var api_key = window.localStorage.getItem('mountmercy_api_key');
  
      if(typeof(device_id)==='undefined' || device_id===null){
          //we dont have a device id so register it and save to local storage. 
          //should only ever enter here once     
          console.log('in the if so going to registerDeviceWithServer ');
  
          app.registerDeviceWithServer(status);        
  
      }
      else{
          app.updateRegId(device_id, api_key, status);
  
      }
  
  },
  
  
  /*
   * For Android Phones
   */
  onNotificationGCM: function(e) {
  
      switch( e.event )
      {
  
          case 'registered':
              if ( e.regid.length &gt; 0 )
              {
  
                  var device_id = window.localStorage.getItem('mountmercy_device_id');
                  var api_key = window.localStorage.getItem('mountmercy_api_key');
  
  
                  if(typeof(device_id)==='undefined' || device_id===null){
                      //we dont have a device id so register it and save to local storage. 
                      //should only ever enter here once     
                      console.log('in the if so going to registerDeviceWithServer ');
  
                      app.registerDeviceWithServer(e.regid);        
  
                  }
                  else{
                      //so we have already registered device on server. Now update reg_id
                      //console.log('in the else so going to updateRegId and app.reg_id is ');
                      //console.log(app.reg_id);
                      app.updateRegId(device_id, api_key, e.regid);
  
                  }
  
              }
              break;
  
          case 'message':
  
              window.location.hash = "article/"+e.payload.article_id;
  
              break;
  
          case 'error':
              //alert('GCM error = '+e.msg);
              break;
  
          default:
             // alert('An unknown GCM event has occurred');
              break;
      }
  }, 
  
  
  onNotificationAPN: function(event) {
  
      console.log('*******event is ************');
      console.log(app.logObject(event));
  
      var pushNotification = window.plugins.pushNotification;
      if (event.alert) {
          navigator.notification.alert(event.alert);
      }
      if (event.badge) {
          console.log("Set badge on  " + pushNotification);
          pushNotification.setApplicationIconBadgeNumber(this.successHandler, event.badge);
      }
      if (event.sound) {
          var snd = new Media(event.sound);
          snd.play();
      }
  },
  
  };
  </code></pre>