# Load Unique SWF each time website visited

**URL:** https://forum.kirupa.com/t/load-unique-swf-each-time-website-visited/10371
**Category:** flash
**Created:** [December 30, 2002, 5:29pm UTC](https://forum.kirupa.com/t/load-unique-swf-each-time-website-visited/10371 "2002-12-30T17:29:03Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![andrthad](https://avatars.discourse-cdn.com/v4/letter/a/e480ec/32.png) [@andrthad](https://forum.kirupa.com/u/andrthad)
#### Post date: [December 30, 2002, 5:29pm UTC](https://forum.kirupa.com/t/load-unique-swf-each-time-website-visited/10371/1 "2002-12-30T17:29:03Z")

</div>

Hi,

I had a question and have never really seen any information on this. Below is a thread that explains how to “SOLVE CACHE PROBLEMS” by loading a uniquely named swf within flash. Does anybody know how to do this in Javascript perhaps so that the visitor does not have to clear their temporary internet files to get the latest swf update? I realize the easy solution might be to just put a revision number/letter on your swf everytime you make an update. Please see below.

Solve Cache Problems when you Load a Movie  
by ilyas usal

When you load a movie, variables, or a text, what you load is put in the cache of your computer by your browser. This can cause problems because if you load files, chances are that you are going to update them quite often, but Flash will look for the files in the cache, that is to say the old ones.  
The solution is to load your files with a unique identifier. Example:

```auto

myIdentifier=Math.round(Math.random()*10000);
loadMovie("myAnim.swf?uniq="+myIdentifier,1);

```

This works also with LoadVariables, LoadMovieNum and LoadVariablesNum.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 30, 2002, 5:31pm UTC](https://forum.kirupa.com/t/load-unique-swf-each-time-website-visited/10371/2 "2002-12-30T17:31:20Z")

</div>

I don’t know of a Javascript way. Well I believe there is a way to have your site not cache anything at all, but I am not sure I remember how to do that.

Anyway, if you have the flash file, why not just do that to the flash file? It would be easier than the javascript way.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 30, 2002, 5:39pm UTC](https://forum.kirupa.com/t/load-unique-swf-each-time-website-visited/10371/3 "2002-12-30T17:39:48Z")

</div>

I got this from Macromedia a while ago

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 30, 2002, 5:41pm UTC](https://forum.kirupa.com/t/load-unique-swf-each-time-website-visited/10371/4 "2002-12-30T17:41:26Z")

</div>

Ah… nice. I knew I remembered seeing a way.

Just as a note: This will keep everything from caching, so if you have any images on your site as well, those will have to load from scratch again. But that will be the same with any other way of doing it outside of Flash.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 30, 2002, 6:49pm UTC](https://forum.kirupa.com/t/load-unique-swf-each-time-website-visited/10371/5 "2002-12-30T18:49:45Z")

</div>

kax,

Thanks for the txt file. I will try to clear the cache through the HTML code.

lostinbeta,

* * *

## Anyway, if you have the flash file, why not just do that to the flash file? It would be easier than the javascript way.

I guess I am a little bit confused. Typically you have a main swf that loads smaller swfs. I understand how to use the code I posted to load the smaller swfs, but the main swf is embedded in the html page. That is why I thought you had to do the main swf through Javascript. However, I guess you could embed a generic swf and load your main swf into the generic one. What do you think? I know. My brain is starting to smoke. Must not think too much.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 30, 2002, 7:41pm UTC](https://forum.kirupa.com/t/load-unique-swf-each-time-website-visited/10371/6 "2002-12-30T19:41:28Z")

</div>

Yeah, you could load your main .swf into the generic .swf.

But if you are using loadMovie, how often does your main movie actually get updated???

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 30, 2002, 8:10pm UTC](https://forum.kirupa.com/t/load-unique-swf-each-time-website-visited/10371/7 "2002-12-30T20:10:53Z")

</div>

Well right now I have most of my content minus some large pics and text files in my main movie (166kb). Eventually I will make each section of the site a loaded swf and my main swf will probably be just my navigation.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [December 30, 2002, 11:36pm UTC](https://forum.kirupa.com/t/load-unique-swf-each-time-website-visited/10371/8 "2002-12-30T23:36:41Z")

</div>

in times of flash 5 and even now out of habit, my methodology in designing online flash projects was (is)  
[pre-loader/title screen] --loadmovie–\> [main movie]

the title screen contained well the title screen as well as the preloader to the actual bulk content movie swf. This of course gave you a fully functional preloader for the entire loaded swf which most of you might have had problems with in Flash 5 (“why does my preloader start at 40%?”).

Anyway, for online testing, the typical method of loading an uncached movie was throwing a random number on the end of the url. Basically:

myIdentifier=Math.round(Math.random()\*10000);  
loadMovie(“myAnim.swf?uniq=”+myIdentifier,1);

though simplified to

loadMovie(“myAnim.swf?”+Math.random(),1);

The round and 10000 is redundant. Anyway, this does the trick just fine and doesnt force a reload of any other of the content on the page.

However, if testing both off the harddrive/in flash and online (or just testing on the harddrive and making sure online content isnt cached) you might want to use the following since appending a random number on the end of a swf and trying to load it off the harddrive will result in a file not found…

```auto

String.prototype.noCache = function(){
	return (_url.substr(0,4) != "file") ? this + "?"+Math.random() : this;
}
// ...
loadMovieNum(("myMovie.swf").noCache() ,1);

```

which will just leave off the random number if the file is being called off the hard drive

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 25, 2003, 1:06pm UTC](https://forum.kirupa.com/t/load-unique-swf-each-time-website-visited/10371/9 "2003-02-25T13:06:46Z")

</div>

let me get this straight, are you telling me that if i put a random number on the end of the url it will force to load an uncached movie ?  
and that it will work online, but not offline (testing in flash) ??

if that´s so, this is worth of tricks of the trade in the best of kirupa, coz it´s so simple… :A+:

thanks for existing my friend 😉

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 25, 2003, 5:06pm UTC](https://forum.kirupa.com/t/load-unique-swf-each-time-website-visited/10371/10 "2003-02-25T17:06:42Z")

</div>

Wow, this is an old thread guig0, and this trick is in the best of Kirupa on page 3 of the tricks of the trade thread. It works, it rocks, I love it.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 25, 2003, 5:54pm UTC](https://forum.kirupa.com/t/load-unique-swf-each-time-website-visited/10371/11 "2003-02-25T17:54:38Z")

</div>

my bad…

i know this is an old thread, i got here with a search… and i folow that thread, tricks of the trade, but i miss that post…☹

and [this](http://www.kirupa.com/developer/actionscript/tricks/cache.asp) link is outdated, so i figured that nobody pay any heed to sen´s post in this thread…
