用于本地数据存储的更大的类似 cookie 的文件(复杂结构的浏览器“缓存”)

发布于 2024-11-19 22:56:07 字数 493 浏览 1 评论 0原文

我正在开发一个基于浏览器的游戏,那里有一张大地图。地图的地形是静态的。因此,我有几千个不会改变的图块(无论它们代表森林、沙漠还是其他),只有上面的玩家可以改变。

因此,我想将我的所有地图存储在玩家的计算机中。我正在使用 Ruby on Rails,这些地图信息从服务器传递到在用户浏览器上运行的 javascript,以便呈现漂亮的地图。但拥有一个 200kb 的 .html 文件,其中包含所有与地图相关的信息,这让我感到非常难过。

解决这个问题最简单的方法是什么?曲奇饼!出色地。我就是这么想的。一个完整的地图信息可以达到近200kb(它们相当大)。一个 cookie 最多可以有 4kb。我不认为实现我的目标的正确方法是创建大量 cookie,例如,为地图的每一行创建一个 cookie。有没有更优雅的方式让这些静态信息位于玩家的浏览器上,而不需要创建大量 cookie?有办法将其缓存在他的浏览器上吗?我的意思是.. 我可以缓存 400kb 的图像,为什么我不能缓存 200kb 的地图结构?

提前致谢! 费尔南多.

I am developing a browser based game, and I have a big map there. The terrain of the map is static. Therefore, I have some thousands of tiles that will not change (whether they represent a forest, a desert, whatever), just the players above it can change.

Hence, I wanted to store all my map in the player's computer. I am working with Ruby on Rails, and those map information are passed from the server to the javascript that runs on the user browser, in order to render a pretty map. But it makes me pretty sad to have a 200kb .html file, containing all those map related information.

What would be the simplest way to solve this issue? Cookies! Well. That's what I thought. A complete map information can get to almost 200kb (they are pretty big). A cookie can have at most 4kb.. I don't feel that the right way to achieve my objective is to create tons of cookies, one for each row of the map, for instance. Is there any more elegant way to have this static information lie on the player's browser, without creating lots of cookies? A way to cache it on his browser? I mean.. I can cache a 400kb image, why can't I cache a 200kb map structure?

Thanks in advance!
Fernando.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

日久见人心 2024-11-26 22:56:07

好吧,HTML 本地存储 为您提供5 MB(尽管数据存储 *作为字符串*,因此容器中可以容纳的实际数据量可能远小于 5 MB,

这一限制是奇怪的,它只是一个。 ><一个href="http://dev.w3.org/html5/webstorage/#disk-space" rel="nofollow">推荐限制;对于另一个,即基于 Webkit 的浏览器使用UTF-16 可以立即将其减少一半(2.5 MB),

浏览器对本地存储的支持很好:IE、Firefox、Safari 4.0+、Chrome 4.0+ 和 Opera 10.5+ 都是 iPhone。 和 2.0 版本以上。

和 Android 分别支持3.0 nofollow">用例。

最后,Paul Kinlan 发布了一个出色的分步指南关于 HTML5Rocks 的教程,我强烈推荐(尽管它已经有一年多了)。

Well, HTML Local Storage gives you 5 MB (though data is stored *as strings*, so the actual amount of data you can fit in the container is likely a lot less than 5 MB.

This limit is oddly fluid. For one thing, it's just a recommended limit; and for another, i.e., Webkit-based browsers use UTF-16, which immediately cuts that in half (2.5 MB).

Browser support for Local Storage is good: IE, Firefox, Safari 4.0+, Chrome 4.0+, and Opera 10.5+. Both iPhone and Android are supported above versions 3.0 and 2.0. respectively.

Using Local Storage to preserve game state appears to be a proto-typical use case.

Finally, Paul Kinlan published an excellent step-by-step tutorial on HTML5Rocks, which i highly recommend (though it's a little more than a year old).

可遇━不可求 2024-11-26 22:56:07

你有没有考虑过将它存储在js文件中?大多数浏览器都会缓存链接的 js 文件,让您只能偶尔提供它。部署起来会非常简单。

Have you considered storing it in a js file? Most browser will cache linked js files, allowing you to only serve it every once in a while. It would be very simple to deploy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文