# Caching dynamically loaded images

**URL:** <https://forum.kirupa.com/t/caching-dynamically-loaded-images/264890>\
**Category:** Uncategorized\
**Created:** [July 1, 2008, 6:43pm UTC](https://forum.kirupa.com/t/caching-dynamically-loaded-images/264890 "2008-07-01T18:43:12Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![offpixel](https://avatars.discourse-cdn.com/v4/letter/o/9e8a1a/32.png) [@offpixel](https://forum.kirupa.com/u/offpixel)\
**Post date:** [July 1, 2008, 6:43pm UTC](https://forum.kirupa.com/t/caching-dynamically-loaded-images/264890/1 "2008-07-01T18:43:12Z")

</div>

hey,

wonder if anyone can shed light on this for me…

ok, i’ve built a site that loads in images (jpeg) dynamically. a php file looks at my image directory, and makes all the filenames into a list… then in flash i take that list and populate an array with the filenames.

then with my interface the user can navigate to the next / previous image, which then uses the movieClipLoader class to load the jpeg into the movieclip, and i use onLoadProgress to throw in some code to control my preloader graphic.

the problem i’m having, is that flash doesn’t seem to be caching the images once already loaded (as in, if the user goes back to a previously loaded image, the image gets preloaded all over again).

the strange thing is… sometimes it caches images, and sometimes it doesn’t… (although with the latest images i’ve uploaded its not caching any) so i’m ruling out anything wrong with my actionscript (famous last words) and was thinking it was an issue with the server or even the jpegs (maybe different compression settings?!).

can anyone offer an explanation?

cheers,  
martin.

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [July 2, 2008, 8:20am UTC](https://forum.kirupa.com/t/caching-dynamically-loaded-images/264890/2 "2008-07-02T08:20:15Z")

</div>

its because you are loading it into the same MC

or you haven’t set up a system to check wether it is already loaded, so you just keep reloading

---

<div class="post-metadata">

**Author:** ![offpixel](https://avatars.discourse-cdn.com/v4/letter/o/9e8a1a/32.png) [@offpixel](https://forum.kirupa.com/u/offpixel)\
**Post date:** [July 2, 2008, 6:14pm UTC](https://forum.kirupa.com/t/caching-dynamically-loaded-images/264890/3 "2008-07-02T18:14:34Z")

</div>

how does that explain it preloading some images and not preloading others though?

---

<div class="post-metadata">

**Author:** ![offpixel](https://avatars.discourse-cdn.com/v4/letter/o/9e8a1a/32.png) [@offpixel](https://forum.kirupa.com/u/offpixel)\
**Post date:** [July 3, 2008, 7:55am UTC](https://forum.kirupa.com/t/caching-dynamically-loaded-images/264890/4 "2008-07-03T07:55:19Z")

</div>

ok, after some testing i’ve worked out what the issue is…

it’s the file size of the jpegs. anything under 200k it caches them. anything above, it always preloads even if you’ve loaded them before.

any ideas of how to combat this?

---

<div class="post-metadata">

**Author:** ![offpixel](https://avatars.discourse-cdn.com/v4/letter/o/9e8a1a/32.png) [@offpixel](https://forum.kirupa.com/u/offpixel)\
**Post date:** [July 3, 2008, 4:03pm UTC](https://forum.kirupa.com/t/caching-dynamically-loaded-images/264890/5 "2008-07-03T16:03:13Z")

</div>

hmm, also seems to be safari specific. firefox seems to cache them ok…

---

<div class="post-metadata">

**Author:** ![pixel\_streamer](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@pixel\_streamer](https://forum.kirupa.com/u/pixel_streamer)\
**Post date:** [July 4, 2008, 5:34pm UTC](https://forum.kirupa.com/t/caching-dynamically-loaded-images/264890/6 "2008-07-04T17:34:58Z")

</div>

some recommended tools to prevent browser cacheing…

[http://www.kirupa.com/forum/showthread.php?t=217850&highlight=cache+prevent](http://http://www.kirupa.com/forum/showthread.php?t=217850&highlight=cache+prevent)

---

<div class="post-metadata">

**Author:** ![offpixel](https://avatars.discourse-cdn.com/v4/letter/o/9e8a1a/32.png) [@offpixel](https://forum.kirupa.com/u/offpixel)\
**Post date:** [July 4, 2008, 7:40pm UTC](https://forum.kirupa.com/t/caching-dynamically-loaded-images/264890/7 "2008-07-04T19:40:27Z")

</div>

[QUOTE=pixel\_streamer;2353693]some recommended tools to prevent browser cacheing…

[http://www.kirupa.com/forum/showthread.php?t=217850&highlight=cache+prevent](http://http://www.kirupa.com/forum/showthread.php?t=217850&highlight=cache+prevent)[/QUOTE]

thanks, but if you read the post you’ll see i’m trying to invoke browser caching 😉

---

<div class="post-metadata">

**Author:** ![pixel\_streamer](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@pixel\_streamer](https://forum.kirupa.com/u/pixel_streamer)\
**Post date:** [July 4, 2008, 10:59pm UTC](https://forum.kirupa.com/t/caching-dynamically-loaded-images/264890/8 "2008-07-04T22:59:29Z")

</div>

It was late.

You can’t force people to increase the size of their browser cache. If their cache is set to 0MB, or something small, flash should reload the images every time, regardless.

I’m not sure why it would not keep the image in the browser cache, but you can always use the bitmapData api to cache the images in memory. As long as you can keep track of what has been snap-shotted, you’re only limited to the user’s memory.

> [@offpixel;2353740](#):
>
> thanks, but if you read the post you’ll see i’m trying to invoke browser caching 😉

---

<div class="post-metadata">

**Author:** ![offpixel](https://avatars.discourse-cdn.com/v4/letter/o/9e8a1a/32.png) [@offpixel](https://forum.kirupa.com/u/offpixel)\
**Post date:** [July 5, 2008, 2:39pm UTC](https://forum.kirupa.com/t/caching-dynamically-loaded-images/264890/9 "2008-07-05T14:39:22Z")

</div>

no worries.

i’ve done some research and it looks to be just a safari specific problem, when images are over 200k.

---

<div class="post-metadata">

**Author:** ![takousarruke](https://avatars.discourse-cdn.com/v4/letter/t/db5fbb/32.png) [@takousarruke](https://forum.kirupa.com/u/takousarruke)\
**Post date:** [July 5, 2008, 6:11pm UTC](https://forum.kirupa.com/t/caching-dynamically-loaded-images/264890/10 "2008-07-05T18:11:30Z")

</div>

What happens to the MC you loaded the photo into when you change photos? because you could do it that when a photo loads it is removed from the array and the movie clip’s alpha is set to 0 when on other pictures.

---

<div class="post-metadata">

**Author:** ![pixel\_streamer](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@pixel\_streamer](https://forum.kirupa.com/u/pixel_streamer)\
**Post date:** [July 6, 2008, 8:46am UTC](https://forum.kirupa.com/t/caching-dynamically-loaded-images/264890/11 "2008-07-06T08:46:29Z")

</div>

That’s a good idea too, but you may also have to toggle the other image’s visible and/or enabled states too, so that mouse-overs and such would function on the correct layers.

> [@takousarruke;2353999](#):
>
> What happens to the MC you loaded the photo into when you change photos? because you could do it that when a photo loads it is removed from the array and the **movie clip’s alpha is set to 0 when on other pictures.**

---

<div class="post-metadata">

**Author:** ![offpixel](https://avatars.discourse-cdn.com/v4/letter/o/9e8a1a/32.png) [@offpixel](https://forum.kirupa.com/u/offpixel)\
**Post date:** [July 6, 2008, 10:35pm UTC](https://forum.kirupa.com/t/caching-dynamically-loaded-images/264890/12 "2008-07-06T22:35:12Z")

</div>

i’m loading in the photos to 2 movieclips… it alternates between the two. basically, an image gets loaded in to the first MC, then the next time i call an image it gets loaded into the second MC so as not to overwrite the MC already loaded on stage… then after the second MC has preloaded the image, i swap the MC’s on stage during a transition, and delete the old one… and so on…

here, to explain easier, this is the site: [www.pavely.com](http://www.pavely.com)

anyway, i’ve seen this problem discussed on another forum here:

> **[ActionScript.org Forums - Powered by vBulletin](http://www.actionscript.org/forums/index.php)**
>
> ActionScript.org Forums

---

<div class="post-metadata">

**Author:** ![pixel\_streamer](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@pixel\_streamer](https://forum.kirupa.com/u/pixel_streamer)\
**Post date:** [July 8, 2008, 3:12am UTC](https://forum.kirupa.com/t/caching-dynamically-loaded-images/264890/13 "2008-07-08T03:12:30Z")

</div>

that’s just how I would handle it.
