Prevent browser caching?

1,131 views
Skip to first unread message

banderberg

unread,
Oct 7, 2008, 11:52:33 AM10/7/08
to SWFObject
My flash object relies on XML files that change from time to time.
The problem is that browsers cache the flash object (or maybe just the
xml data?).

The result being that a user re-visiting the site won't see the
changes unless they clear their browser cache.

How can I use SWFObject to prevent browsers from caching my flash
object/data so that users always see the fresh data?

Rusty

unread,
Oct 7, 2008, 12:02:40 PM10/7/08
to SWFObject
In your flash file add a time stamp to your xml querystring. Although
the browser will cache your flash file, adding a timestamp will 'fool'
the browser into thinking each time the xml file is loaded it is a new
xml file.

Aran Rhee

unread,
Oct 7, 2008, 7:07:06 PM10/7/08
to swfo...@googlegroups.com
Just to clarify, you should do something like:

flashvars = {}
flashvars.playlist = "playlist.xml?t=" + new Date().getTime();

This will give you a millisecond accurate unique number on every
refresh.


Also, please search the lists before asking questions. The same question was
asked and answered a few days ago...


Aran

banderberg

unread,
Oct 8, 2008, 12:58:08 PM10/8/08
to SWFObject
I don't have access to the original flash source code I don't think..
I only have a SWF file.

How can I do it then?

Jimbo

unread,
Oct 8, 2008, 1:03:52 PM10/8/08
to swfo...@googlegroups.com
Try this in your swf embed code (example is 2.1 - dynamic embed, but you can adapt it) it will load a fresh instance of the swf, and should load a fresh instance of you xml file from the fresh swf:

<script type="text/javascript">
var flashvars = {};
var params = {};
var attributes = {};
swfobject.embedSWF("mySwfApp.swf?t=" + new Date().getTime(), "mySwfApp", "550", "400", "9.0.0", false, flashvars, params, attributes);
</script>

*********** REPLY SEPARATOR ***********
t

Aran Rhee

unread,
Oct 8, 2008, 6:19:51 PM10/8/08
to swfo...@googlegroups.com
Jimbo.

While this will ensure a new flash file, it will still load the same xml
file and cache it. Each file the browser requests / caches is totally
independent, so just because you have a new flash file, when a request goes
out to load the XML file, it will still come from cache if loaded before.

The code I supplied yesterday will work if you are able to supply the
location of the XML file externally. If the location / name of the XML file
is baked into the swf, then you have some issues as you have no real
control... You would have to do things like trying to control the caching
rules of certain files on the server-side, and if you are on shared hosting,
then you can forget that as an option...

Aran

-----Original Message-----
From: swfo...@googlegroups.com [mailto:swfo...@googlegroups.com] On
Behalf Of Jimbo
Sent: Thursday, 9 October 2008 4:04 AM
To: swfo...@googlegroups.com
Subject: Re: Prevent browser caching?


Jimbo

unread,
Oct 9, 2008, 7:23:47 AM10/9/08
to swfo...@googlegroups.com
Thanks,
Thought it might be worth a try. So if there is no access to the fla/xml path, there is no way to prevent caching the xml file? Too bad.
I found that even when you add the cache-buster to the actionscript call to a file, if you don't put the cache-buster in the swf embed, you will have caching problems with IE - I use a page counter occasionally, that calls a php file to update the page loads number, and use a cache-buster to load the php file via actionscript in the swf. But if I do not add the cache-buster to the swf embed code as well, IE will not load the php file/update the number correctly. So for recent IE iterations, you need both, I believe.
http://jimbo.us/as3/count/

jimbo

*********** REPLY SEPARATOR ***********
a

Mr. Apache

unread,
Oct 22, 2008, 2:07:48 PM10/22/08
to SWFObject
It really depends on your server.. if you have apache its quite easy
to setup @http://www.askapache.com/htaccess/mod_rewrite-fix-for-
caching-updated-files.html
Reply all
Reply to author
Forward
0 new messages