# Older, deleted image keeps loading instead of newer one with the same name

**URL:** <https://discourse.processing.org/t/older-deleted-image-keeps-loading-instead-of-newer-one-with-the-same-name/20746>\
**Category:** Beginners\
**Created:** [May 11, 2020, 11:11am UTC](https://discourse.processing.org/t/older-deleted-image-keeps-loading-instead-of-newer-one-with-the-same-name/20746 "2020-05-11T11:11:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vera](https://avatars.discourse-cdn.com/v4/letter/v/b3f665/32.png) [@Vera](https://discourse.processing.org/u/Vera)\
**Post date:** [May 11, 2020, 11:11am UTC](https://discourse.processing.org/t/older-deleted-image-keeps-loading-instead-of-newer-one-with-the-same-name/20746/1 "2020-05-11T11:11:51Z")

</div>

I’m using the web editor.  
I have an array with a number of images in it. I added a new image and I accidentally uploaded the wrong file first. Because the naming structure is related to the array, the second, right image has the same name.

```auto
const NUM_IMG = 3;
let images = [];
let currentImg = 0;

function preload(){
for (let i = 0; i < NUM_IMG; i++) {
   images[i] = loadImage("image" + i + ".png");
  }
}
function draw(){
image(image[currentImg], 0,0);
}

```

By clicking a button currentImg goes through the array one at a time.

What happens is that even though I deleted the first file and then uploaded the second one, the first one keeps loading in the array. Even when I deleted the second one again, and there wasn’t even a file with the right number anymore, the image kept loading.

I tried deleting all cookies, and restarting Chrome, and nothing helps.  
I know this happened to me before, and the way I’ve ‘solved’ it both times is copying the code to a new project and re-uploading the (correct) files there.  
But I’d like to know why this happens and how I can actually solve this.

---

<div class="post-metadata">

**Author:** ![Sven](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sven/32/8293_2.png) [@Sven](https://discourse.processing.org/u/Sven)\
**Post date:** [May 11, 2020, 2:26pm UTC](https://discourse.processing.org/t/older-deleted-image-keeps-loading-instead-of-newer-one-with-the-same-name/20746/2 "2020-05-11T14:26:51Z")

</div>

Hello @Vera,

It’s hard to tell what’s going on from that code excerpt. Could you share the sketch and the name of the image that causes you trouble?

Inside `draw`, the code refers to an array named `image` (a function, actually), but it should probably be `images`. That doesn’t explain the weird cache behavior, though.

---

<div class="post-metadata">

**Author:** ![Vera](https://avatars.discourse-cdn.com/v4/letter/v/b3f665/32.png) [@Vera](https://discourse.processing.org/u/Vera)\
**Post date:** [May 14, 2020, 2:49pm UTC](https://discourse.processing.org/t/older-deleted-image-keeps-loading-instead-of-newer-one-with-the-same-name/20746/3 "2020-05-14T14:49:47Z")

</div>

Hi Sven,  
You’re right that it should have been `images`.  
[This](https://editor.p5js.org/VeraJunior/sketches/8kxUIJxUB) is a sketch which has currently this problem. The image background2.png should be a rectangle the same size as the other 2, but it still is the older one which is shorter.

---

<div class="post-metadata">

**Author:** ![Sven](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sven/32/8293_2.png) [@Sven](https://discourse.processing.org/u/Sven)\
**Post date:** [May 14, 2020, 3:26pm UTC](https://discourse.processing.org/t/older-deleted-image-keeps-loading-instead-of-newer-one-with-the-same-name/20746/4 "2020-05-14T15:26:45Z")

</div>

I think it looks right in my browser, so it’s probably your browser that has the image cached.

 ![Screenshot of p5.js sketch: dress up game featuring a bear.](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/fe3ca3b58e387def7783f66475d6cad1cf33a106.png)

You could try deleting _Cached images and files_ aggressively, selecting _All time_ for _Time range_. Hopefully, that helps.

 ![Clear browsing data window in Chrome, with Time range and Cached images and files highlighted.](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a4f9f5f4b57eb3588255410fab00fa9ab396e46d.png)

---

<div class="post-metadata">

**Author:** ![Vera](https://avatars.discourse-cdn.com/v4/letter/v/b3f665/32.png) [@Vera](https://discourse.processing.org/u/Vera)\
**Post date:** [May 14, 2020, 7:22pm UTC](https://discourse.processing.org/t/older-deleted-image-keeps-loading-instead-of-newer-one-with-the-same-name/20746/5 "2020-05-14T19:22:22Z")

</div>

Thank you, I tried that clearing the cached images, but it didn’t have any effect. But I noticed that if I close the editor and leave it alone for half a day or longer, everything is working right again. So I definitely agree that there is some form of caching going on, but I just don’t know where.
