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

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

问题描述

我将开发可以在移动设备(智能手机)上运行的网络应用程序.在应用中,运营商会输入一些业务数据,运营商也会在封闭的空间中输入这些数据,在那里网络信号可能不可用.

因此,需要离线模式.在这种模式下,运营商可以输入数据,这些数据会存储在浏览器端,网络可用后,数据会被发送到服务器并保存在数据库中.

我发现了两种可能的解决方案:

  1. 将值存储在 JavaScript 内存中.无法在浏览器崩溃或页面重新加载后幸免于难.
  2. 将值存储在 HTML5 LocalStorage 中.需要支持 HTML5 的浏览器,并保证此存储是持久的(关闭浏览器应用后不会刷新).

因为我还没有为智能手机开发 Web 应用程序,而且我对它们的经验很少,所以我有一个问题:

特定智能手机(Android、Windows Mobile、Windows Phone、iPhone)上的特定浏览器的 JavaScript 内存和 HTML5 LocalStorage 限制是什么?

我知道理论上 HTML5 LocalStorage 应该是 5MB,而 JavaScript 内存应该取决于设备资源,至少应该是 5MB,但是对于智能手机来说如何?例如我注意到在 Windows Phone 6.5 上,

解决方案

根据我的经验,对于上面提到的平台,您可以可靠地押注至少 5MB.将您的数据保持在该级别以下,您应该非常安全.

阅读这篇文章.http://diveintohtml5.info/storage.html 它有一些不错的信息,但还不是全部准确,尤其是说你不能达到极限的部分.
我知道一个事实,在 iPhone 上,一旦达到限制,手机会询问用户是否要留出更多空间.(有点准确,但不完全)

在 Android 平台上,堆内存限制设置为 12MB.其他平台不清楚.由于您将在某种 webcontainer(Webkit 或其他)中运行,因此我不会太担心.容器本身非常擅长管理内存和实现文件缓存以最大程度地减少占用空间.

我建议您将内存优化等放在最后.谁知道呢,你甚至可能不需要它.不要过早优化.

附注:
看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天全站免登陆