LocalStorage limit on PhoneGap

2019-01-23 12:27发布

问题:

There is usually a limit of 5MB on localStorage on browsers, including iPhone's Safari.

Since PhoneGap has the access higher security privileges including access to other storage mechanisms on the device, in theory they should be able to eliminate the limit of 5MB.

For example, it should be able to get around the usual restrictions by storing the data on a file, etc while keeping the API compatible with localStorage javascript object.

Is this done? Or is PhoneGap limited to the same 5MB?

回答1:

PhoneGap doesn't do anything out of the ordinary to extend the default limits. On Android, I get 2.5M characters in localStorage (Strings in JavaScript are UTF-16).

You can find default limits for most browsers here: http://dev-test.nemikor.com/web-storage/support-test/

This was helpful in understanding the limitations, and I used the code to create a simplified test PhoneGap app.



回答2:

PhoneGap has File API that should not be affected by browser local storage limits but don't know if there exist any abstraction to make it behave as HTML5 local storage "backend".



回答3:

If you want to store a large amount of data you should not do that in localStorage, there are databases and files for that kind of need. localStorage is a key-value datastore, it's use is limited and it should not be "hacked" to fit all needs.



回答4:

Localstorage is something which is provided by the browser.

Localstorage is not something which is available on a device, either a mobile phone or a desktop, that is leveraged by a browser.

Since it is something which the browser provides there is no way, we can change/increase it using Phonegap since your Phonegap app runs inside the browser.

If you want more storage space, you can use a technique which Phonegap can access like a file storage or SQlLite.