Sonntag, 14. August 2011

Preventing the Browser from caching a .swf-File (very useful in dev-mode)

Relevant Snippet from the embedding html-template:

// Note: appending the current time as query-parameter for the url
// will prevent the internet explorer from caching the swf

var currentDate = new Date();
swfobject.embedSWF(
"${swf}.swf?" + currentDate.getTime(), "flashContent",
"${width}", "${height}",
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);


Notes:
As you see the trick is to append the query-string with a random number, so the browser must assume the resource you are requesting is never the same.
For production use you should consider to replace the current time with the version-number of the release.

Keine Kommentare:

Kommentar veröffentlichen