momo
momo

Reputation: 3474

Cordova + Backbone.js - Delay main.js load until deviceready is fired

I am adapting an existing Backbone.js project to Cordova. Everything works fine except that, on iOS, I can't use console.log on the main.js. I am using the Cordova console plugin (org.apache.cordova.console) in order to be able to print messages to the console on iOS, and this is working fine in other scripts but not in main.js. I am sure this is due to deviceready not being fired yet when main.js is executing.

How can I do to load main.js after deviceready is fired?

Upvotes: 0

Views: 353

Answers (1)

xumet
xumet

Reputation: 216

My main file always is something like this:

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady(){
    // Start the app
    App.initialize();
}

var App = (function(){

    var App = {};

    App.initialize = function(){
        console.log("App initialize");
        // Your code here...

    };

    return App;

}());

I call it app.js

Upvotes: 1

Related Questions