Prevent browser cache

Hi @slackmoehrle, @owen, @nantas

As instruction to upload web desktop version to server, I just need to copy it over, but there is a cache problem, after copy update files to server, browser still keep old version, I have to use private mode to see new changes.
Is there anything I can do to prevent this

Sounds like you need cache busting. It’s needed most for production, if you’re just doing local development, then there’s plenty of other solutions.

so basicly what we do, we having index.php file which including index.html file or we renaming .hmtl file to .php and in side having fllowing code, which get sha of current gamin.min.js and in this case browser will re-download JS file if it is new.

  <?php
  if (file_exists("cached/game.min.js")) {
	    chmod("game.min.js", 0777);  //changed to add the zero

	$sha1 = sha1_file("cached/game.min.js");
	$new_file = "cached/game.min-".$sha1.".js";
	
	if (!file_exists($new_file)){
		
		if (copy('cached/game.min.js', "$new_file")){
		 	echo "<script cocos src=\"$new_file\"></script>";
		} 
		
		else {
			echo "<script cocos src=\"cached/game.min.js\"></script>";
		}
	} else {
		echo "<script cocos src=\"$new_file\"></script>";
	}
} else {
	
}

?>

Thank guys, but just this solution for particular file, I can have script updated, image assets udpate, do we have general solution for cocos creator project

Typically we’ll deploy our releases to a dated folder on some static hosting service. Then have our page reference the latest release folder. I can’t think of anyway of keeping the releases in the same folder at all times that would avoid cache hits.

1 Like

In v1.6, we will introduce a mechanism to append a md5 suffix to each resources to be published on the server.

And the browser cache pain will be resolved.

1 Like

Hi,
When will v1.6 supposed to be released?

Hi, this is not actually a Creator problem but a common issue with HTML5,JS apps and games (also webpages of course).

Wrap your js and assets folder inside a v01, v02, v03…etc, folder and then djust the urls path in your index.html.
That should fix the problem. For every new version, create a new folder.

Regards,

Yeah, for now I can manually do that. I’ve by passed the problem by edit index.html and main.js, add version suffix to imported javascript files

v1.6 is scheduled in the next two month, but it might also be delayed, so you might need to solve this issue as @jrosich suggested ATM.