# Supabase Storage: Preventing Cached Images When Updating Files + Replace storage file issue

**URL:** <https://community.weweb.io/t/supabase-storage-preventing-cached-images-when-updating-files-replace-storage-file-issue/17601>\
**Category:** Ask us anything\
**Tags:** workflows, supabase, weweb\
**Created:** [April 3, 2025, 6:20pm UTC](https://community.weweb.io/t/supabase-storage-preventing-cached-images-when-updating-files-replace-storage-file-issue/17601 "2025-04-03T18:20:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![joaosander](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/joaosander/32/12584_2.png) [@joaosander](https://community.weweb.io/u/joaosander)\
**Post date:** [April 3, 2025, 6:20pm UTC](https://community.weweb.io/t/supabase-storage-preventing-cached-images-when-updating-files-replace-storage-file-issue/17601/1 "2025-04-03T18:20:24Z")

</div>

I built a profile picture CRUD system and ran into a caching issue with Supabase Storage.

When uploading an image, you need to define a path in the storage bucket. The problem is: if you reuse the same path every time, the new image will be uploaded successfully, but due to caching, the old image will still be displayed. The browser continues to serve the cached version, and only after clearing the cache does the new image appear.

To solve this, every time I update the image, I first delete the existing file and then upload the new one. However, this only works reliably if I also change the file path each time. To ensure a unique path, I append a timestamp using `new Date().getTime()`.

Using Supabase’s “replace storage file” workflow doesn’t solve this issue, since the file path remains the same and the cache continues to serve the old image.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/6/6b3694e9630e826d0cccd73bcca424f5d30431a2.png)  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/6/6adf83bd8c603465a48f995ec8d9acea6fcd3c66.png)

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [April 3, 2025, 7:39pm UTC](https://community.weweb.io/t/supabase-storage-preventing-cached-images-when-updating-files-replace-storage-file-issue/17601/2 "2025-04-03T19:39:45Z")

</div>

Easiest way is to use unique names. Or to set cache to a very low number, but then you lose the cache itself.

---

<div class="post-metadata">

**Author:** ![Yaj](https://avatars.discourse-cdn.com/v4/letter/y/eb8c5e/32.png) [@Yaj](https://community.weweb.io/u/Yaj)\
**Post date:** [April 3, 2025, 9:13pm UTC](https://community.weweb.io/t/supabase-storage-preventing-cached-images-when-updating-files-replace-storage-file-issue/17601/3 "2025-04-03T21:13:53Z")

</div>

I can’t remember if there’s anymore to what I done but I’ve just done a normal upload with the correct path and file so it’ll overwrite then I retrieve the URL and i store it in a variable with a ?v= concatenated on. I can’t remember the specifics or if this is all you need but I mananged to get around your issue and I think it’s just doing this below. You use this value to get the image.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/d/da9804756a9894332870604d413dd1b8cf7ae5ca.png)

Just realised I think i also set the upload cache to be 0

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/7/71741d739016bc296c4f3b67cff6fed5d0270bfa.png)

---

<div class="post-metadata">

**Author:** ![joseph](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/joseph/32/11340_2.png) [@joseph](https://community.weweb.io/u/joseph)\
**Post date:** [June 3, 2025, 12:14am UTC](https://community.weweb.io/t/supabase-storage-preventing-cached-images-when-updating-files-replace-storage-file-issue/17601/4 "2025-06-03T00:14:20Z")

</div>

Omigosh! I forgot about the cache and upload issue, and I hadn’t considered the query string parameter in years! Thanks–I just did the same now.

---

<div class="post-metadata">

**Author:** ![Brunor](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@Brunor](https://community.weweb.io/u/Brunor)\
**Post date:** [September 29, 2025, 2:59pm UTC](https://community.weweb.io/t/supabase-storage-preventing-cached-images-when-updating-files-replace-storage-file-issue/17601/5 "2025-09-29T14:59:20Z")

</div>

I realized that this method doesn’t work if you update the image of the same record more than once in a short period of time, less than a minute for example. Even using cache control with the value 0.

Another observation is that the way your formula is written, it will concatenate a new parameter into your URL whenever the image is updated, instead of replacing the current parameter.

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [September 29, 2025, 5:35pm UTC](https://community.weweb.io/t/supabase-storage-preventing-cached-images-when-updating-files-replace-storage-file-issue/17601/6 "2025-09-29T17:35:58Z")

</div>

When requesting the image, just append a timestamp with the last update of that image to the url. So [PROJECT\_ID].supabase.com/…/your\_bucket/img?cache=[TIMESTAMP\_HERE], this will invalidate the cache.
