I am creating a guest list application for my company using PHP, Javascript / jQuery / Ajax, JSON and localstorage. It will be used on smartphones: primarily Iphone 4. I use localstorage as my cache, since the search part of the application should work offline.
I'm having performance issues when searching the guest list.
The application flow looks like this (for this exam I am working with a guest list that contains 600 guests)
1. Retrieve all guests from the server using PHP encoding using JSON and send back to js via AJAX. It works great.
2. Parse the PHP responseText (called phpData) using JSON.Parse:
var parsedMysqlData = JSON.parse(phpData);
which gives us a JSON.Array containing 600 objects that look like this:
Object: {
Id: Int
EventId: int
guestInfo: string
guestlist: string
guestName: string
reference: string
total: int
used: int
}
3. Save the JSON.Array for the localstorage user using JSON.Stringify:
localStorage.setItem(0, JSON.stringify(parsedMysqlData));
4. when the user starts the search, we get his search string and then return our guest list using JSON.parse in localstorage as follows:
var currentGuestlist = JSON.parse(localStorage.getItem(0));
And then iterate through our objects using this for-loop, which tries to match its search string with our guests with the currentGuestlist array:
for (i=0; i<currentGuestlist.length; i++) {
// match 'currentGuestList[i]['name']' with what the user typed in search form
}
For some reason, it takes a lot of time on iPhone 4. Searching for 600 items will freeze the iphone for about 4 seconds before returning matches.
, JSON localStorage, JSON, localStorage, . JSON , localStorage, . , , - , JSON? localStorage , , ?
, , , .