Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Cordova/PhoneGap only support single page mobile apps

Tags:

cordova

After reading its tutorials, I still feel confused. Do I need to include the cordova.js and initialize the app.initialize(); on each single page? Or as long as the index.html is loaded, I wouldn't need to include cordova.js and init it on any other pages?

like image 642
Franva Avatar asked Jan 01 '14 15:01

Franva


3 Answers

It depends! If you are using Cordova in companion with jQM or any other ajax-like frameworks, it is NOT necessary to load cordova.js on each page. It is only necessary to load it in your index.html and it will stay there available even if you change the page in another html.

The reason is that in jQM things are loaded in ajax like fashion and they stay in the DOM, that is why the cordova library is available through the DOM life. If you include cordova.js on each page you will have multiple declarations and that could lead into problems. Be aware of that.

I have been working in an app using single page apps, each page on an independent HTML, which was benefitial for our purposes for mantainability and it allow different people to work on other pages without messing all in just one file. We just load cordova and other common libraries in the index.html and all is working fine. For specific pages that requires special code, I load the required scripts for each page, so the library code does not remain in the DOM when other I change pages, to keep the DOM as light as possible and clean.

If you want to include cordova on each page, just be aware yo check first if the library is not already loaded. What I do recommend it to check for the deviceready event in all pages just to stay safe.

Single or multipage app development decision depends on your needs and situation.

like image 116
VicM Avatar answered Oct 23 '22 19:10

VicM


In mobile devices is crazy to load everything each time, especially if haven't wifi connection.

Take a look on this, is very simple way to make modular app with one only html: https://github.com/charnekin/api

like image 27
JSG33kC0d3 Avatar answered Oct 23 '22 18:10

JSG33kC0d3


Yes. You have to include the cordova.js on each page. Although you don't need to subscribe to Cordova-related events on each page if you don't need access to device-specific functionality on that page and you could use regular HTML pages with combinations of JS and CSS. Although this is possible, this is not recommended way to do things in Cordova applications, since each time you will navigate to new page, user will notice that. The Cordova 'best practices' is to use Single Page Application and don't use multiple pages for different screens.

You could look at article at the link http://floatlearning.com/2011/03/developing-better-phonegap-apps/ for another set of good advices which take in consideration when start working with Cordova

like image 30
codevision Avatar answered Oct 23 '22 18:10

codevision