PDA

View Full Version : How to prevent caching of swf files



jankratochvil
November 22nd, 2005, 03:18 AM
How to prevent caching of swf files?
Have somebody any link on tutorial.
I read this page http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_14743 but | know is it possibilitity to generate somehow every time a new SWF name.
How can I make it?
Thanks :thumb2:

VersusMG
November 22nd, 2005, 03:26 AM
why not just put a non caching header in the html file? That would not let it download.

:)

mathew.er
November 22nd, 2005, 03:32 AM
Well, if you pass a variable to flash trough its URL, it will be taken as a different swf. You can add it to the src attribute of embed tag like here:
<embed src="http://www.example.com/file.swf?uselessVar=randomStuffxyz" bla bla bla />
If you assign that variable everytime some random string or number, it will be like a new swf and downloaded again, but I'm pretty sure that this isn't the cleaner nor the best solution ;)

jankratochvil
November 22nd, 2005, 04:40 AM
Ok. how can i pass the var uselessVar to the file.swf?
Manually or can i use some script, which can make it.
Thank you


Well, if you pass a variable to flash trough its URL, it will be taken as a different swf. You can add it to the src attribute of embed tag like here:
<embed src="http://www.example.com/file.swf?=randomStuffxyz" bla bla bla />
If you assign that variable everytime some random string or number, it will be like a new swf and downloaded again, but I'm pretty sure that this isn't the cleaner nor the best solution ;)

brianmanden
November 22nd, 2005, 05:18 AM
I have a code snippet that might get you on the way ;)



function myRandomUrl() {
uselessVar="";
for (i=0; i<=50; i++) {
uselessVar = uselessVar+chr((Math.random()*25)+97);
}
return uselessVar;
}
addToUrl = myRandomUrl();
// You can use getURL or whatever fits your situation best
getURL("http://www.domain.com/dir/jankratochvil.swf?"+addToUrl, _blank);


You can find the ascii codes here (http://www.pcxt-micro.com/ascii.html)!

Barn
November 22nd, 2005, 11:50 AM
why not just put a non caching header in the html file? That would not let it download.

:)
If the SWF doesn't download, it cannot be viewed.

No matter what scheme, a SWF will be in the user's cache -- all you can do is prevent the browser from reloading it from the cache; you cannot prevent the download to the cache, so do not think of these schemes as being any sort of security measure; all it can be is a means of preventing outdated material from being displayed.

jasarius
November 27th, 2005, 06:43 PM
Okay...I hate to barge in one the post, but same question. I know there's no way to keep the browser from caching the the .swf, but which one of those resolutions is the best?

I didn't quite get the 'uselessVar' script. Can I get a breakdown by line or something to help me understand?

Thanks.

mathew.er
November 28th, 2005, 11:43 AM
The "uselessVar" solution that brianmanden showed is for loading swf file from flash. The one I showed is by modifying HTML code, but princip is same. You have to alter swf's URL so it will different everytime you load it and thus browser will download it again, thinking its different file. You get to this by adding some useles variable to the URL after "?" character... that flash solution generates and adds random characters to the url so as you would have done when using HTML method.

System-Idle
November 28th, 2005, 03:42 PM
getURL("my.swf?"+Math.random()*1000, _blank);

sonicdoomx
November 28th, 2005, 08:12 PM
Solution sounds good, but would it work if I have different swf files and use loadMovie to load the others on the main swf?

dColumbus
November 29th, 2005, 01:53 AM
http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_14743

or

http://oddhammer.com/tutorials/dont_cache/

or

http://www.laflash.org/forum/archive/index.php/t-533.html

:blush:

jasarius
December 8th, 2005, 12:17 PM
Okay, I got the concept...it just makes sense, but I don't know how to apply.

I'm currently trying to make sure the content on the site (http://www.flashbacksdanceclub.com) I'm working on gets updated.

I have a main flash that loads in smaller movies. How would I apply the random suffix properly to the swf in order for it to load the newest content. I only need it to update maybe every four hours give or take, not everytime.

Even better, If I could dynamically assign a new version and then it checks to see if there is a new version...if so, it loads, if not, it doesn't.

I know it makes perfect sense to you, but I just use the behaviors module to load into an empty clip (see example below):


on (release) {
//load Movie Behavior
if(this.contact == Number(this.contact)){
loadMovieNum("form_management.swf",this.contact);
} else {
this.contact.loadMovie("form_management.swf");
}
//End Behavior
}
How would I take this and make it to where it would load the latest version? I know I haven't done it right for my HTML pages so I don't want to crash and burn on this as well.

Do I need to write a script or something or does Flash/browser automatically recognize everything I put behind the .swf extension as some type of command?

Thanks.

Barn
December 9th, 2005, 07:59 PM
Try this:


on (release) {
stgFile = "form_management.swf?nocache="+getTimer();
//load Movie Behavior
if (this.contact == Number(this.contact)) {
loadMovieNum(stgFile, this.contact);
} else {
this.contact.loadMovie(stgFile);
}
//End Behavior
}

The behavior, by the way, is testing the variable contact (somewhat ineffectually, as it were) to see whether it is a Number or a Movieclip, and if the former, presumes you want to load the SWF into a level, whereas if the latter, presumes that the SWF is to load into the movieclip contact.