简体   繁体   中英

WebSQL or LocalStorage - iOS / Cordova / JavaScript

we're just redesigning an application we build 1 year ago. We would like to improve some steps inside our application and speed up things a bit. Now our login process takes up to 15 seconds. There is much data which gets saved in our WebSQL DB.

We tried to save all that data without sense into localStorage and the process now takes a maximum of 2 - 3 Seconds which is much faster than our WebSQL Solution.

So now i wondered why this is like it is and took a look into the WWW. If we want now to change our whole process from WebSQL to LocalStorage, is there anything we have to consider?

Maybe there is a great and fast storagePlugin for cordova - i didn't found that one, do you know one?

Is localStorage a good way to save data instead of using a WebSQL Database?

Thanks in advance!

The main limitation on local storage is storage capacity. On iOS you are limited to 5Mb per application, so if you are storing a lot of data, you could soon reach this limit. With WebSQL, iOS gives you 50Mb. See this page for storage capacities across platforms.

You may want to consider using something like lawnchair as an abstraction layer; it has a series of adapters so you can keep the interface the same in your code and try swapping in different storage via the adapter mechanism. By default it uses local (DOM) storage, but has adapters for WebSQL and IndexedDB among others.

If you require A LOT of storage capacity, consider using something like this plugin which allows you to use a native SQLite database with unlimited capacity.

If performance is an issue, you may want to for-go an abstraction layer such as lawnchair and manually write the SQL to interact with database, so you can optimise it. I created this example project which uses the SQLite plugin above with optimised SQL. On my iPad2/iOS 8.3 it's able to perform 15000+ inserts in around 1.4 seconds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM