The simplest solution is to append an additional querystring parameter such as the updated date
or revision id
like in this previous answer I provided. You can do this by inheriting MediaProvider
and override GetMediaUrl()
:
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, MediaUrlOptions 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
, the modified parameter will be updated whenever there is a change causing CloudFlare to request the media asset from the CD server.
If you need to track downloads of certain media items then you can track Download events in Sitecore, although they may tracking individually in external analytics tools as @JB has stated.