Can I save images or load images from the client, instead of sending them every time?
I'm using node.js and socket.io, and I'm making a game. There are quite a few sprites I need to send to the client, so to lower the bandwidth I thought about storing the data on the clients computer. For now, the basic idea would be that it just downloads once, and then gets saved to the clients computer. But how do I gain control of the client's files? And how can I save pictures/general data on the client's computer?
Here is what I'm doing:
self.sources =
[
[//trees, 0
"re开发者_如何学Pythons/images/enviornment/trees/tree_1_1.png",//0
"res/images/enviornment/trees/tree_1_2.png",//1
"res/images/enviornment/trees/tree_1_3.png",//2
"res/images/enviornment/trees/tree_1_4.png",//3
], //there are many other pictures, but this is just the concept
];
self.images = new Array();
for (i = 0; i < self.sources.length; i++)
{
self.images.push([]);
for(t = 0; t < self.sources[i].length; t++)
{
self.images[i][t] = new Image();
self.images[i][t].src = self.sources[i][t];
}
}
Browsers will cache the images, but the type of expiration is chosen by the server, and depending on the type, it may also be up to the server to properly handle requests for files where the client's cache is up to date.
If you want it to "just work," use Express.
To learn more about http caching, try this: http://betterexplained.com/articles/how-to-optimize-your-site-with-http-caching/
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
You should take a look at the html5 offline applications spec. Beware, it's not supported everywhere yet.
精彩评论