by Vesselin Vassilev
Last Updated On Jun 23, 2018
public class SdConfig : ConfigSection{ [ObjectInfo(Title = "JS Script Version", Description = "Current version of the js file")] [ConfigurationProperty("jsScriptVersion", DefaultValue = "22062018")] public string JsScriptVersion { get { return (string)this["jsScriptVersion"]; } set { this["jsScriptVersion"] = value; } } }@if (!Telerik.Sitefinity.Services.SystemManager.IsDesignMode){ var jsVersion = Config.Get<SdConfig>().JsScriptVersion; @Scripts.Render("CdnUrl/js/scripts.js?v=" + jsVersion)}<script src="CdnUrl/js/scripts.js?v=22062018"></script>using SitefinityWebApp.Custom.Configuration;using Telerik.Sitefinity.Configuration;using Telerik.Sitefinity.Web;namespace SitefinityWebApp.Custom.CacheVariations{ /// <summary> /// Output cache will be based on the value of the JsScriptVersion config value. /// Any change in that config will invalidate the page cache (or rather create a new page cache variation) /// </summary> public class JsVersionCacheVariation : CustomOutputCacheVariationBase { /// <summary> /// This could be any custom string /// </summary> public override string Key { get { return "bundle-js-version"; } } /// <summary> /// This is what tells Sitefinity how to distinguish the different page cache variations. /// We will have different page cache variations for different js script versions. /// </summary> /// <returns></returns> public override string GetValue() { var config = Config.Get<SdConfig>(); return config.JsScriptVersion; } }}using SitefinityWebApp.Custom.CacheVariations;using System.Web.Mvc;using Telerik.Sitefinity.Mvc;using Telerik.Sitefinity.Web;using Telerik.Sitefinity.Web.UI;namespace SitefinityWebApp.Mvc.Controllers{ /// <summary> /// This widget registers custom js version based output cache variation - meaning the same URL will have different /// html output depending on the value of the js version in the SdConfig. /// This widget will go to the base template. /// </summary> /// <returns></returns> [ControllerToolboxItem(Name = "JsVersionCacheDependencies", Title = "Js Version Based Cache", SectionName = "Admin Widgets", CssClass = "sfMvcIcn")] [IndexRenderMode(IndexRenderModes.NoOutput)] public class JsVersionCacheDependenciesController : Controller { public ActionResult Index() { // register custom cache Variation based on the js version configuration value PageRouteHandler.RegisterCustomOutputCacheVariation(new JsVersionCacheVariation()); // the widget has no html output itself return new EmptyResult(); } }}