JavaScript内存和智能手机上的HTML5 LocalStorage限制 [英] JavaScript memory and HTML5 LocalStorage limitations on smartphones

查看:161
本文介绍了JavaScript内存和智能手机上的HTML5 LocalStorage限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将开发网络应用,它应该适用于移动设备(智能手机)。在应用程序中,操作员将输入一些业务数据,操作员将在封闭的空间中输入这些数据,因为网络信号不可用。所以,有一个需要离线模式。在这种模式下,操作员可以输入数据,这些数据将存储在浏览器端,并且在网络变得可用后,数据将被发送到服务器并保存在数据库中。

我找到了两种可能的解决方案:


  1. 将值存储在JavaScript内存中。无法在浏览器崩溃或页面重新加载后存活。

  2. 将值存储在 HTML5 LocalStorage 中。需要支持HTML5的浏览器,并确保此存储空间持久(关闭浏览器应用程序后不刷新)。

还没开发出适用于智能手机的网络应用程序,而我对它们几乎没有经验,我有这样的问题:

JavaScript内存和HTML5 LocalStorage的局限性特定智能手机上的特定浏览器(Android,Windows Mobile,Windows Phone,iPhone)?我知道理论上HTML5 LocalStorage应该是5MB,而JavaScript内存应该是5MB取决于设备资源,这应该至少为5MB,但它对于智能手机来说如何? F.G.我在Windows Phone 6.5上注意到,



阅读这篇文章。 http://diveintohtml5.info/storage.html 它有一些很好的信息块,但并不全是准确的,特别是说你不能忍受限制的部分。

我知道一个事实,即在iPhone达到极限时,手机会询问用户是否想要更多空间。 (准确但不完全)


在Android平台上,堆内存限制设置为12MB。不确定其他平台。既然你要在某种webcontainer(Webkit或其他)中运行,我不会太担心它。容器本身在管理内存和实现文件缓存方面非常出色,可以最大限度地减少它们的占用空间。



我建议您保留最后的内存优化等。谁知道,你甚至可能都不需要它。不要过早优化。



PS:

看看Phonegap: http://phonegap.com/


I'm going to develop web application which should work on mobile devices (smartphones). In the application the operator will input some business data, and the operator will type this data also in closed spaces, where network signal can be unavailable.

So, there is a need for offline mode. In such mode operator can input data, which will be stored on browser side, and after the network becomes available, the data will be send to the server and persisted in database.

I've found out 2 possible solutions:

  1. Store the values in JavaScript memory. Will not survive browser crash or page reload.
  2. Store the values in HTML5 LocalStorage. Requires browser with HTML5 support and guarantee that this storage will be persistent (no flush after closing the browser app).

Because I've not developed the web application for smartphones yet, and I have little experience with them, I have the question:

What are the JavaScript memory and HTML5 LocalStorage limitations for particular browsers on particular smartphones (Android, Windows Mobile, Windows Phone, iPhone)?

I know that theoretically HTML5 LocalStorage should be 5MB, and JavaScript memory should depend on device resources, which should be at least 5MB, but how it is for Smartphones? F.g. I've noticed on Windows Phone 6.5, that the jStorage page, using userData for older IE, is not persisting data on this device (maybe it got flushed after each page refresh, during to limited resources).

update In the answer to the question of max size of local storage values there's great link to the simple application which tests local storage limitations, and according to the test I've made, the local storage can be increased on Opera Mobile 11 without browser's limitation, the user must simply accept the request for more space. The limits are there the device's limits.

Here's the QR code to the app:

And the app itself: http://arty.name/localstorage.html

解决方案

In my experience you can reliably bet on 5MB minimum for the platforms you mention above. Keep your data below that level and you should be pretty safe.

Read this article. http://diveintohtml5.info/storage.html it has some nice nuggets of info, but it's not all accurate, especially the part that says you cant up the limit.
I know for a fact that on iPhone once you reach the limit the phone will ask the user if they want to allow more space. (Sort of accurate, but not entirely)

On Android platforms the heap memory limit is set at 12MB. Not sure about the other platforms. Since you are going to be running in some kind of webcontainer (Webkit or other) I wouldn't worry too much about it. The containers themselves are pretty good at managing memory and implementing file caches to minimize their footprint.

I recommend you leave the memory optimizations and such for last. Who knows, you might not even need it. Dont optimize prematurely.

PS:
Look at Phonegap: http://phonegap.com/

这篇关于JavaScript内存和智能手机上的HTML5 LocalStorage限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆