7

My workflow is sometimes the following:

  1. Delete many images from the media library at once (named for example, 01.jpg, 02.jpg, 03.jpg...).
  2. Re-upload a series of images with the same file names (01.jpg, 02.jpg, 03.jpg...).

The media library retains and display shows the old images as thumbnails and previews, even though they are deleted.

Obviously this problem is avoidable by adding images with distinct file names, but I wondered if there were some better way that works regardless of naming convention. Or something else that I'm completely missing?

Thanks.

5
  • You sure that's not just your browser caching the images? CTRL + F5'ed?
    – t31os
    Commented Feb 22, 2011 at 2:01
  • @t31os Thanks for your response. I'm sure it is just my browser caching the images. But (I should have specified) I'm not the only user. I'd prefer not to have to tell my users to refresh every time they delete something or the clunkiness of building in a page refresh as part of image deletion.
    – user3402
    Commented Feb 22, 2011 at 17:51
  • +1'ed both the current answers(with my last two votes for the day), using a query variable is a good method for cache busting.. :)
    – t31os
    Commented Feb 22, 2011 at 18:04
  • Isn't there also a WP plugin to force regenerate thumbnails?
    – noel saw
    Commented Feb 23, 2011 at 1:18
  • Thanks, everyone. I'm ok on the CMS front-end. There's no way to cache bust the media gallery/library without editing the core though, right? mod_expires might be my best bet.
    – user3402
    Commented Feb 23, 2011 at 1:18

3 Answers 3

4

@t31os Thanks for your response. I'm sure it is just my browser caching the images. But (I should have specified) I'm not the only user. I'd prefer not to have to tell my users to refresh every time they delete something or the clunkiness of building in a page refresh as part of image deletion.

But, that's just why we have browser caching — to prevent the same image from loading everytime we call it again. The browser sees it as the same image.

You can make a little workaround by calling the image like this: http://yoursite.com/images/01.jpg?v1 and http://yoursite.com/images/01.jpg?v2 - this would load the same image 2 times.

1
3

This is a browser cache issue, not a WordPress media library issue. The reason you see the old images in the media gallery is because you used the same file name and your browser is trying to save time and bandwidth by loading the versions it already has.

There are two ways to solve this problem.

Cache Busting

Add a query variable (?v=5) to the end of your image names as used on the front-end. This won't affect the media gallery ... but it will prevent people from seeing cached versions of old images on the front-end. For reference, this is the same method we use in WP core to force the browser to re-download updated JavaScript files.

mod_expires

You can tell your server (Apache) to set a custom "expires" date and time for different images either based on the extension (all jpg or png files) or the filename, if you want to get really granular. This is more of an advanced trick, but you can use this to immediately flush everyone's cache whenever you upload new images.

-1

Actually, it's the cache issue. You can clear the browser cache to see changes. If your're using any Cache plug-in in your WordPress site then also clear that.

1
  • Welcome to wpse! How is this answer different from @EAMann? This seems to be exactly the same answer but with less information, if its different please consider adding more information. As it stands this is a copy of @EAMann answer. Commented Nov 25, 2021 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.