I'm making an online scoreboard with a replay feature. Every second of a game for the scoreboard is stored in a record in a database in XML format so that it can be parsed. The user should be able to choose a game to replay and JS will replay the game on a second-by-second basis.
我正在制作一个带有重播功能的在线记分牌。记分板的每一秒游戏都以XML格式存储在数据库中的记录中,以便可以对其进行解析。用户应该能够选择要重播的游戏,JS将逐秒重放游戏。
As each game lasts ~15 minutes with a lot of events, a game will have around ~3mb of data attached to it. I figure the best way to do this would be to create a temporary XML file based on the game data for a JS file to preload to the browser to parse and display.
由于每场比赛持续约15分钟,有很多赛事,一场比赛将附加约3mb的数据。我认为最好的方法是根据游戏数据创建一个临时XML文件,以便将JS文件预加载到浏览器进行解析和显示。
So, would this be the best method, and if not what would be?
那么,这是最好的方法,如果不是,那会是什么?
Note: It's being made in PHP.
注意:它是用PHP制作的。
1 个解决方案
#1
1
Sending 3 MB of data and parsing it on the client can take quite some time. To make the sure the data takes less space and is parseable faster, you could use JSON instead of XML.
发送3 MB数据并在客户端上解析可能需要相当长的时间。为了确保数据占用更少的空间并且可以更快地解析,您可以使用JSON而不是XML。
Also, do you need the whole file at once? If not, I'd suggest an AJAX "loader" routine that does the following:
另外,您是否需要立即使用整个文件?如果没有,我建议一个AJAX“加载器”例程执行以下操作:
- Read x minutes worth of game data
- 阅读x分钟的游戏数据
- Parse it and add it to the data pool
- 解析它并将其添加到数据池中
- Request the x minutes, jumping to 2 when the data has loaded.
- 请求x分钟,数据加载后跳转到2。
The ideal value for x is a question of network speed vs replay speed. Each request would add some HTTP header and TCP overhead, so test it with different network conditions.
x的理想值是网络速度与重放速度的问题。每个请求都会添加一些HTTP头和TCP开销,因此请使用不同的网络条件对其进行测试。
#1
1
Sending 3 MB of data and parsing it on the client can take quite some time. To make the sure the data takes less space and is parseable faster, you could use JSON instead of XML.
发送3 MB数据并在客户端上解析可能需要相当长的时间。为了确保数据占用更少的空间并且可以更快地解析,您可以使用JSON而不是XML。
Also, do you need the whole file at once? If not, I'd suggest an AJAX "loader" routine that does the following:
另外,您是否需要立即使用整个文件?如果没有,我建议一个AJAX“加载器”例程执行以下操作:
- Read x minutes worth of game data
- 阅读x分钟的游戏数据
- Parse it and add it to the data pool
- 解析它并将其添加到数据池中
- Request the x minutes, jumping to 2 when the data has loaded.
- 请求x分钟,数据加载后跳转到2。
The ideal value for x is a question of network speed vs replay speed. Each request would add some HTTP header and TCP overhead, so test it with different network conditions.
x的理想值是网络速度与重放速度的问题。每个请求都会添加一些HTTP头和TCP开销,因此请使用不同的网络条件对其进行测试。