Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load cordova.js before the app #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

YifanM
Copy link

@YifanM YifanM commented Aug 14, 2018

I faced an issue where cordova.js wasn't loaded when index.js was executed.

In particular, window.cordova was undefined at this part. It would load later.

if (window.cordova) {
  document.addEventListener('deviceready', startApp, false);
} else {
  startApp();
}

I found the problem was that the <script type="text/javascript" src="cordova.js"></script> was placed below the </body>. This would lead to the script loading after the app.

To fix this, cordova.js should be placed somewhere such as before </head> (which is where the css is linked). This ensures we have cordova when the app bootstraps.

This can be verified by debugging the value of window.cordova in index.js with the current and new positions for the script tag. I only tested this on Android however.

This is dangerous since otherwise it will ignore the deviceready event on a device, which could lead to using cordova before it's ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant