Standard methods
You may know there are several methods to prevent caching of swf (or other) files:
1) Adding fake random parameter to the url of the file. In this case the best practice is adding the current time as parameter:
in ActionScript 3:
|
new URLRequest("file.swf?"+new Date().time) |
in Javascript:
|
var d = new Date(); var t = d.getTime(); swfobject.embedSWF("file.swf?nocache="+t, .... ); |
But then a browser will never cache the content. Therefore it’s not the best solution especially when the size of swf is quite large.
2) Using META tags in html headers like Pragma: No-Cache or Expires:
Expires tag says to browser when the file should expire from the cache
|
<META http-equiv="Expires" content="Thu, 04 Feb 2010 14:00:00 GMT"> |
Pragma: No-Cache directs the browser to not cache the file at all.
|
<HEAD><META http-equiv="PRAGMA" content="NO-CACHE"></HEAD> |
All these methods are described at official Adobe site: http://kb2.adobe.com/cps/147/tn_14743.html
Using Expires HTTP-Header
The most of web-servers have ability to add http-header to response of particular file or site\folder in general. My solution is adding
Expires header to files which you are trying to prevent caching.
Expires value should specify the current date. Hence browser will always receive expired data.
So what happens when browser receives expired data? An expired item can be still valid. So browser performs validation of the item by sending
If-Modified-Since request to the server. The server checks modification date of requested file. And according to result it either sends a new content or response with status code
304 (not modified).
So if you specify immediate expiration of content in HTTP-header then as soon as you update a file it will be cleared from cache and reloaded by browser. If the file is not changed then browser will get it from cache.
You can refer very nice article of Wayne Shea about cache expiration here:
http://articles.sitepoint.com/article/save-cash-optimize-cache
Add Expires header on server side
You can find the ways to add Expires header on IIS below.
IIS 5
You need to select a file or folder and select Properties… in context menu. Then select HTTP-Headers tab and check Expire Content Expiration and after check Expire Immediately:
IIS 7
Select HTTP Response Headers in feature list. Right-click -> Set Common Headers… Check Expire Web Content -> Immediately :