Is PhoneGap worth it?

Here are some my thoughts about PhoneGap when I used it to develop a client / server phone application to display store offer listings both in text views and on a map.

These thoughts only apply to when I was using PhoneGap a number of months ago, maybe some of these thoughts are not relevant as PhoneGap stands today. I have not used PhoneGap again since this time because I have not needed to develop a phone software application.

Ok so my thought about PhoneGap is that the documentation is not so good. Although it appears to look good there where a lot of times I followed the documentation and it did not work, alternatively it just was not documented.

If the documentation did not work I generally looked around the web but who knows which version of PhoneGap the web tutorials / Q&A was meant for.

Many times I tried what was written on the web and it did not work, alternatively sometimes it did work but only after I read another piece of documentation that told me how to set it up correctly to get it to work but this was not mentioned in the initial piece of documentation I was reading.

LocalStorage options are not so good. Depending on the type of project clients are going to need quite a lot of local storage. Web SQL was an option but apparently it has been or is being deprecated.

IndexedDB was another option but this is only supported on a small number of platforms like Windows and Blackberry.

It is not supported by PhoneGap on IOS or Android. LocalStorage was the only other option that PhoneGap provides and this is the option I went with. However LocalStorage is limited to 5MB of data and only stores data in key / value pairs.

Plugin support is reasonable but depending on the number of devices the phone application has to run on it can be limited. You may find find a plugin that works on IOS but not Android or a plugin that works on Android and not IOS but not both.

No support for native GUI components. This means PhoneGap applications can look like web pages unless serious efforts are made to make them look more like a native PhoneGap. Not a big issue, just depends how native you want the application to look and I guess a lot of customers will want the native look and feel and with all the fancy fold out menus and special effects this could take a quite a bit of work to do.

Maybe there is a library out there that helps with this, I do not know? However I doubt the library will ever give quite the same feel as building the phone application using traditional native programming languages and tools.

The resolution for the PhoneGap application was not very good. For IOS the application was running at 480px by 320px and this is not a matter of simple configuring some setting in the config file.

At the time I was using PhoneGap this was the resolution that PhoneGap supported even though IOS supported a much greater resolution at that time. IPhone 5 1136 x 640 and IPhone 5s 1920×1080.

So these are my thoughts on PhoneGap. It is suited to some types of phone applications and I would use it again if the need called for it and the scope of the project was not too complex but for the really hardcore type phone applications I would stick to using the native programming languages and tools.

HTML5 Web Storage Implementation

Recently I have been working on a client project which required the ability to store data from a server on the users local machine. In this case the users local machine was a mobile phone, IOS, Android, Windows etc.

It does not really matter on the platform as it will be stored using the mobile phones web browser and most of the browsers are modern enough to have the new HTML5 Web Storage mechanism.

In actual fact the data will be stored using PhoneGaps implementation of HTML5 Web Storage. PhoneGap is a framework that allows the user to write phone software in HTML5, CSS3 and Javascript.

So for all intents and purposes it is like writing a responsive website that works on mobile phone browsers but is actually compiled and runs like a real native software application. PhoneGap interfaces with HTML5 Web Storage for the purposes of using HTML5 Web Storage mechanism.

So to store the data locally I found WebSQL and HTML5 Web Storage to be my options. Although WebSQL looked perfect for storing and querying the data, it is actually being depreciated and will no longer be in use as a standard in future. So my mind was made up for me in that case.

Web Storage on the other hand seems very straightforward, but this would be the case as it does not include the more complex features of querying the data. Web Storage works by storing name / value pairs. So we can say colour = red, or age = 25, name / value.

Like I said this is straightforward but we cannot say give me all persons over the age of 20 for example there is no querying mechanism.

In actual fact there is no mechanism for even storing multiple persons with ages to begin with. The real structured data is left to the programmer to implement and like wise with querying the structured data.

So what approach did I use?

I decided to store the value of the data as a JSON string and the name would be the table name. So for my project this data needed to be fetched from the web server and stored locally using the Web Storage.

I setup a PHP web server that returned a JSON response upon request via the client. The client did this using JQuery standard Ajax request functions. When I got this JSON response from the server which was basically a dump of a particular database table on the server in JSON format.

I stored it in local storage using the particular database table name for the name value. So in the persons / ages example this would be Person = Encoded JSON string of all data in the server Person table.

So now we have all of data for a particular table from the server stored in local storage. I just repeat this process for all the tables I want to store locally. We now have our data.

But what about querying this data?

Well JQuery does not come, out of the box anyway, with functions for querying JSON data. So a developer might think, I know, I will decode the JSON string and write my own functions for querying this data, possibly by putting the data into foreach loops and returning the records when the data matches the developers expectations. Well that is one way to do it however I am not sure how efficient that would be.

Looping through lots of data just to find single records cannot be very efficient however this is JQuery (Javascript) we are talking about, it is not as if it was designed to do this kind of thing anyway, plus Javascript processing power is becoming more powerful as a whole now in modern day browsers.

It is still not a server side language though and does not query a real database like MySQL which was designed for efficiency, but this is not expected of Javascript anyway.

I do not want to talk about efficiency too much as it is easy to slate querying data this way when a lot of internal libraries might just be doing the same thing under the hood anyway. I cannot imagine there being another way to do it with standard Javascript / JQuery when it comes to the rock bottom.

Anyways enough talk of how querying the decoded JSON data might be handled at a lower level. We as developers have libraries for this kind of thing and luckily someone has written a plugin to do this task anyway called json-sql. Here is the link to the library …

www.trentrichardson.com/jsonsql/

The json-sql library allows the developer to query a JSON string using SQL like syntax. Admittedly it only includes a very small subset of the standard SQL functions but it is most certainly good enough for most purposes, selecting, ordering and where clause. So I used this library to query my JSON data.

So that is pretty much it, the project has a web server which sends JSON responses to the client, data is stored in JSON strings in the client local Web Storage and the data is queried using the json-sql library before being displayed to the user.

This is the way I implemented a server / client, DB synchronized, local storage web software application.