Adding a unique URL parameter will force the browser to request the updated image, as mentioned by both the other answers. You'll also face this same issue if you are using a CDN by the way and using the same technique works well in this situation too. I provided code for an updated MediaProvider
in my post about CDNs. This will ensure you don't need to upload the image with a different name and stops the issue of re-linking the image to your components.
Create a new MediaProvider
which inherits from the default Sitecore one and override the GetMediaUrl()
appending the revision or date property. You only need to append one of these and which one you append is down to preference - both achieve the same goal.
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Resources.Media;
namespace MyProject.CMS.Custom.Media
{
public class MediaProvider: Sitecore.Resources.Media.MediaProvider
{
public override string GetMediaUrl(MediaItem item)
{
Assert.ArgumentNotNull((object)item, "item");
return this.GetMediaUrl(item, MediaUrlOptions.Empty);
}
public override string GetMediaUrl(MediaItem item, MediaUrlOptions options)
{
Assert.ArgumentNotNull((object) item, "item");
Assert.ArgumentNotNull((object) options, "options");
string mediaURL = base.GetMediaUrl(item, options);
mediaURL = Sitecore.Web.WebUtil.AddQueryString(mediaURL, new string[] {"revision", ((Item)item).Statistics.Revision });
//OR, you only need one of these
mediaURL = Sitecore.Web.WebUtil.AddQueryString(mediaURL, new string[] {"modified", ((Item)item).Statistics.Updated.ToString("yyyyMMddHHmmss") });
return mediaURL;
}
}
}
And then create a config patch to use the new provider.
<mediaLibrary>
<mediaProvider>
<patch:attribute name="type">MyProject.CMS.Custom.Media.MediaProvider, MyProject.CMS.Custom</patch:attribute>
</mediaProvider>
</mediaLibrary>
The URLs generated for the media items should now be in the format /-/media/path-to/image.png?la=en&h=123&w=123&hash={hash}&modified=20170817134500
Media.AlwaysAppendRevision
setting. Take a look at this post for more details.