- Home /
Turn off / invalidate browser cache
We update our game frequently, but our users' browsers have cached old versions. Is there any way to tell the browsers that they should download the .unity3d
file anew? It would be okay to turn off browser cache completely since our game is teeny.
Thanks.
Answer by Maarten · Dec 07, 2010 at 11:07 AM
They should automaticly download the new one as soon as you upload a new one. This because of the "changed" headers.
However, you can add a random value to the URL. Then it seems that it should load a new page everytime. Use javascript for this.
For example:
var timestamp = (new Date()).getTime();
var url = window.location + '?time=' + timestamp;
window.location = url;
Clever trick. Strange, maybe there is clock skew or something causing the browser not to detect it. I have only had reports of it not working within a few hours of the upload...
By "should", I assume you mean "according to the HTTP protocol", not "Unity follows the HTTP protocol". I'm still looking for some evidence that Unity even makes a request (and so sends or gets any headers) until the Expires time is reached.
Answer by Thelo · Feb 22, 2011 at 03:40 AM
Adding a query string to the .unity3d file's URL will not always work, for whichever reason - browser caches are really fickle beasts. The way I solved this problem has been to always append the build number to the published .unity3d file, like MyGame436.unity3d. That way, no matter what strange caching algorithm the user's browser uses, it'll redownload the game for sure, since it perceives it as a completely new file.
I'm doing the renaming automatically through a batch file that I run every time I want to publish a new version of the game to the server. It reads the current SVN version of the file through subwcrev (let's say it's 436), then copies MyGame.unity3d as MyGame436.unity3d and changes the .html file to reference MyGame436.unity3d.