1

I would like to develop a web application for browser and mobile application with Cordova. I want to maintain only one code base and have Cordova references to the code for the web application. Right now I have the code for web application in one folder and a Cordova project in another folder.

Cordova can use most of the code for the web application, but I need to add some code for mobile specific behaviors which are not applicable to a desktop browser. In this case, I don't want to add those to the code for web application.

So I'm seeking a good practice of sharing code among web application and mobile application (There's also one problem that's not solved. Cordova hardcode www and the source for the web application is in another location). And I'm new to Cordova. I'm not certain which is better to serve those html, js, css files in mobile application. Should I pack all of them into the app or load the ones on demand when the app is running.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Mao
  • 107
  • 7

1 Answers1

0

Be aware that if you are serving the code from a remote server, the connection to the server may go down at any time, such is the nature of mobile devices. If this happens, it may prevent navigation through the application and cause user interface issues.

But if you want to serve the Cordova specific sections from the actual web application, you could use techniques from this answer in order to tell your web application that you are browsing from Cordova. You could then use this in conjunction with a server side scripting language such as PHP to selectively serve the Cordova specific sections.

For example, if you are serving the page from a PHP script which sets $cordova to TRUE if Cordova is detected, otherwise false, you can do something like this

<body> <a href="...">common section</a> <?PHP if($cordova == TRUE): ?> cordova specific section <?PHP endif; ?> </body>

Community
  • 1
  • 1
gsp8181
  • 358
  • 1
  • 2
  • 11