From be0bacd895314500fd5c0a8e4a88e35c4451cd05 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 8 Mar 2016 17:23:54 +0100 Subject: [PATCH] Ensures all angular views are cache busted so browser cache is not an issue after upgrading. --- src/Umbraco.Web.UI.Client/src/app.js | 34 +++++++++++++++---- .../HtmlHelperBackOfficeExtensions.cs | 8 ++++- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/app.js b/src/Umbraco.Web.UI.Client/src/app.js index e2a12bc876..64f468712a 100644 --- a/src/Umbraco.Web.UI.Client/src/app.js +++ b/src/Umbraco.Web.UI.Client/src/app.js @@ -22,15 +22,35 @@ var packages = angular.module("umbraco.packages", []); //module is initilized. angular.module("umbraco.views", ["umbraco.viewcache"]); angular.module("umbraco.viewcache", []) - .run(function($rootScope, $templateCache){ - /** For debug mode, always clear template cache to cut down on + .run(function($rootScope, $templateCache) { + /** For debug mode, always clear template cache to cut down on dev frustration and chrome cache on templates */ - if(Umbraco.Sys.ServerVariables.isDebuggingEnabled){ - //$rootScope.$on('$viewContentLoaded', function() { - $templateCache.removeAll(); - //}); + if (Umbraco.Sys.ServerVariables.isDebuggingEnabled) { + $templateCache.removeAll(); } - }) + }) + .config([ + //This ensures that all of our angular views are cache busted, if the path starts with views/ and ends with .html, then + // we will append the cache busting value to it. This way all upgraded sites will not have to worry about browser cache. + "$provide", function($provide) { + return $provide.decorator("$http", [ + "$delegate", function($delegate) { + var get = $delegate.get; + $delegate.get = function (url, config) { + + if (Umbraco.Sys.ServerVariables.application && url.startsWith("views/") && url.endsWith(".html")) { + var rnd = Umbraco.Sys.ServerVariables.application.version + "." + Umbraco.Sys.ServerVariables.application.cdf; + var _op = (url.indexOf("?") > 0) ? "&" : "?"; + url += _op + "umb__rnd=" + rnd; + } + + return get(url, config); + }; + return $delegate; + } + ]); + } + ]); //Call a document callback if defined, this is sort of a dodgy hack to // be able to configure angular values in the Default.cshtml diff --git a/src/Umbraco.Web/HtmlHelperBackOfficeExtensions.cs b/src/Umbraco.Web/HtmlHelperBackOfficeExtensions.cs index 75e628851e..3f38ae35ec 100644 --- a/src/Umbraco.Web/HtmlHelperBackOfficeExtensions.cs +++ b/src/Umbraco.Web/HtmlHelperBackOfficeExtensions.cs @@ -3,8 +3,11 @@ using System.Linq; using System.Text; using System.Web; using System.Web.Mvc; +using ClientDependency.Core.Config; using Microsoft.Owin.Security; using Newtonsoft.Json; +using Umbraco.Core; +using Umbraco.Core.Configuration; using Umbraco.Web.Editors; namespace Umbraco.Web @@ -30,6 +33,7 @@ namespace Umbraco.Web /// public static IHtmlString BareMinimumServerVariablesScript(this HtmlHelper html, UrlHelper uri, string externalLoginsUrl) { + var version = UmbracoVersion.GetSemanticVersion().ToSemanticString(); var str = @"