Some useful tips on Flash, caching and Php
Making the test for some strange flash cache behaviour I've learned some useful tips:
You can be sure a movie will be loaded appending a query string to the file name:
You can force the user to reload a movie when you release a new version:
Actionscript:
-
clipname= "cache"+VERSION+"-clip.swf";
-
loadMovie(clipname, target); //Loaded
-
//After the first load the movie is cached:
-
loadMovie(clipname, target2); //Cached
And use a .htaccess file (ModRewrite required):
Apache:
-
RewriteEngine on
-
RewriteCond %{REQUEST_URI} cache([0-9]+)-(.*)\.swf(.*)$
-
RewriteRule ^cache([0-9]+)-(.*)\.swf(.*)$ $2\.swf [L]
Only when you change the VERSION variable (pass it with flashVars) the movie will be reload, otherwise it will be loaded from the browser cache.
You can make cacheable a file downloaded through php:
Be sure to set the correct content type:
PHP:
-
$filename= "clip.swf";
-
if($fp){
-
-
}
-
}
-
else
-
{
-
}
Without Last-Modified or ETag headers flash doesn't cache the files.