2

We are facing a caching issue for the pre-optimized-min file generated by the Sitecore cli gulp task. As this task adds/updates the file in the Sitecore, which only updates the timestamp of the file.

The problem resides in the extension method of ItemExtensions below, which always uses created date for versioning, which never changes. This results in caching issue as the URL and version never change.

enter image description here

One possible solution is I overwrite the caller methods with the new extension method, the second option is to update the gulp file to always delete the file before upload, however, I would like to know how other folks are dealing with this problem.

3
2

It seems the issue has been fixed in later versions of SXA so sitecore might be able to provide a hotfix for this otherwise you would need to overide the methods. If you look at 10.1 implementation the method looks like this:

public static string BuildAssetPath(this Item item, bool addTimestamp = false)
    {
      MediaItem mediaItem = (MediaItem) item;
      MediaUrlBuilderOptions urlBuilderOptions = new MediaUrlBuilderOptions();
      urlBuilderOptions.set_Thumbnail(new bool?(true));
      string str1 = MediaManager.GetMediaUrl(mediaItem, urlBuilderOptions).Replace("&thn=1", string.Empty).Replace("?thn=1&", "?").Replace("?thn=1", string.Empty);
      string str2 = str1.Contains("://") ? str1 : StringUtil.EnsurePrefix('/', str1);
      if (addTimestamp)
      {
        string queryString = "t=" + item[Sitecore.XA.Foundation.SitecoreExtensions.Templates.Statistics.Fields.__Updated];
        str2 = str2.MergeQueryString(queryString, "");
      }
      if (Settings.Media.get_AlwaysAppendRevision())
        return HashingUtils.ProtectAssetUrl(str2);
      return str2;
    }
1
  • Thanks @cristi this is what I intended to do in first solution. – Mrunal Brahmbhatt Mar 2 at 8:54
1

We got a patch from the Sitecore support here is the link.

The hotfix was built specifically for Sitecore XP 9.3.0 and SXA 9.3.0, and you should not install it on other Sitecore versions or in combination with other hotfixes, unless explicitly instructed by Sitecore Support.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.