Working on my main site I realize that Google Chrome NEVER EMPTY IT’S CACHE, never, and, I don’t know if it’s a html cache control problem or what, but, I make changes to my site and every time I refresh the page (still on chorme, actually Firefox some times does the same) the page still the same, I tried meta and php headers for cache control but still the same, more specific, loaded xml, images, mp3, etc.
I decided to do some research surfing on the web a lot, testing a lot more and here is a series of tips to deal with really dynamic content for Flash. I use all of this guidelines together. If there is other ways you know to avoid caching issues you are free to leave comments and links, except for those trying to convince me to buy some cheap meds, enlarge stuff or download a lot of aerosmith songs for free…
HTML meta tags and Server side Headers
Add this meta tags inside the head tag on your website, after the title tag, just to know where you place it
<meta http-equiv="Pragma" content ="no-cache" />
<meta http-equiv="Cache-Control" content ="no-cache" />
Ok, this is the first part. You can actually send some http headers using the proper fuction depending on your prefered server side langage.
PHP
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
Note: gmdate php function gets the current datetime mark, I put a series of more info links at the end of this post.
ASP
<% Response.CacheControl = "no-cache" %>
ASP.NET (VB)
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.Cache.SetNoStore()
Here is other more agressive ASP.NET code (C#)
Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1
Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1
Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1
Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.1
I’m not writing every known language cause sintax are similar and each web based language has a method to send headers.
Loading the SWF
This method requires in this case SWFObject 2+ to load the swf movie, the concept is, you can request any file followed by a unique request, for example, like doing a GET to file.php?id=
Here is the code
//remember to use Math.floor to remove floating points
var cachecontrol = Math.floor(Math.random()*99999);
var flashvars = {};
var params = {};
var attributes = {id:"movie"};
swfobject.embedSWF("movie.swf?"+cachecontrol, "flashcontent", "100%", "100%", "10.1.0", "expressInstall.swf", flashvars, params, attributes);
Loading assets with Action script
I will assume that you know how to load files with Actionscript 3. Like in the last tip, we are requesting a file with a unique id (kind) on the URLRequest parameters
var cachecontrol:String = Math.floor(Math.random()*9999).toString();
loader.load(new URLRequest("asset.<ext>?uid="+cachecontrol));
.ext refers to a valid file extension for the proper class like Loader, URLLoader or Sound, I’m 90% sure that also can work with multiple loader solutions like BulkLoader.
If you are on AIR development, you can set some code to check the local cache before making a new request, or simple disable the cache but remember this ir AIR only.
I hope this basic tips can help you guys.
For more info on all this stuff you can check the folowing links
Actionscript reference on loading content
PHP Header function
ASP.NET AddHeader method
Further reading about cache
HTTP Request
