智能手机上的 JavaScript 内存和 HTML5 LocalStorage 限制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7267354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaScript memory and HTML5 LocalStorage limitations on smartphones
提问by Danubian Sailor
I'm going to develop web applicationwhich 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.
我将开发应在移动设备(智能手机)上运行的Web 应用程序。在应用中,运营商会输入一些业务数据,运营商也会在封闭的空间中输入这些数据,在那里网络信号可能不可用。
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:
我发现了两种可能的解决方案:
- Store the values in JavaScript memory. Will not survive browser crash or page reload.
- 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).
- 将值存储在 JavaScript 内存中。不会在浏览器崩溃或页面重新加载后幸免于难。
- 将值存储在HTML5 LocalStorage 中。需要支持 HTML5 的浏览器,并保证此存储将是持久的(关闭浏览器应用程序后不会刷新)。
Because I've not developed the web application for smartphones yet, and I have little experience with them, I have the question:
因为我还没有为智能手机开发 Web 应用程序,而且我对它们的经验很少,所以我有一个问题:
What are the JavaScript memory and HTML5 LocalStorage limitations for particular browsers on particular smartphones (Android, Windows Mobile, Windows Phone, iPhone)?
特定智能手机(Android、Windows Mobile、Windows Phone、iPhone)上特定浏览器的 JavaScript 内存和 HTML5 LocalStorage 限制是什么?
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 jStoragepage, using userDatafor older IE, is not persisting data on this device (maybe it got flushed after each page refresh, during to limited resources).
我知道理论上 HTML5 LocalStorage 应该是 5MB,而 JavaScript 内存应该取决于设备资源,至少应该是 5MB,但是对于智能手机来说呢?Fg 我注意到在 Windows Phone 6.5 上,jStorage页面,使用userData用于旧的 IE,没有在这个设备上持久化数据(也许它在每次页面刷新后被刷新,在有限的资源期间)。
updateIn the answer to the question of max size of local storage valuesthere'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.
更新在对本地存储值的最大大小问题的回答中,有一个指向测试本地存储限制的简单应用程序的很好的链接,根据我所做的测试,可以在 Opera Mobile 11 上增加本地存储而不受浏览器的限制,用户必须简单地接受更多空间的请求。限制是设备的限制。
Here's the QR code to the app:
这是应用程序的二维码:
And the app itself: http://arty.name/localstorage.html
和应用程序本身:http: //arty.name/localstorage.html
采纳答案by n4rzul
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.
根据我的经验,对于上面提到的平台,您可以可靠地押注至少 5MB。将您的数据保持在该级别以下,您应该非常安全。
Read this article. http://diveintohtml5.info/storage.htmlit 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)
阅读这篇文章。http://diveintohtml5.info/storage.html它有一些不错的信息块,但并不都是准确的,尤其是说你不能达到极限的部分。
我知道一个事实,在 iPhone 上,一旦达到限制,手机会询问用户是否要留出更多空间。(有点准确,但不完全)
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.
在 Android 平台上,堆内存限制设置为 12MB。其他平台不清楚。由于您将在某种 webcontainer(Webkit 或其他)中运行,因此我不会太担心。容器本身非常擅长管理内存和实现文件缓存以最大限度地减少它们的占用空间。
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/
PS:
看Phonegap:http: //phonegap.com/
回答by RedRoosterMobile
just tested out your link: check localstorage
刚刚测试了您的链接:检查 localstorage
- Chrome 16.0.912
- iPad2 IOS 5.0.1
- iPhone 3GS
- 铬 16.0.912
- iPad2 IOS 5.0.1
- iPhone 3GS
all go until 2.600.000 characters. Since UTF-8 has 4 bytes just multiply it by four and you get the total bytes.
一直到 2.600.000 个字符。由于 UTF-8 有 4 个字节,只需将其乘以 4 即可得到总字节数。
10400000 bytes = 9,918 MegaBytes
10400000 字节 = 9,918 兆字节
回答by MikeC
On my lowly HTC Wildfire S using Android 2.3.5 your page stopped at 2,600,000. I'm impressed it got that high.
在我使用 Android 2.3.5 的低端 HTC Wildfire S 上,您的页面停在 2,600,000。我印象深刻,它变得如此之高。
On Firefox 16.0.1 desktop it stopped at 5,200,000 which is consistent with what about:config quota is defined at.
在 Firefox 16.0.1 桌面上,它停在 5,200,000 处,这与 about:config 配额的定义一致。