From bb527996b94aaf2b2d746971b6cbb788f3eac517 Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 7 Mar 2014 10:40:27 +1100 Subject: [PATCH] Moves the JsNoCache to a real readable file instead of an embedded string (now an embedded file resource), updates it's logic to not append the hash to any dependencyhandler.axd request, fixes case sensitivity checking on the URLs, changes the cdf + umb version to be a nice shorter hash of the two. --- src/Umbraco.Web/Search/ExamineEvents.cs | 14 ++++---------- .../UI/JavaScript/JsInitialization.cs | 13 ++++++++++--- src/Umbraco.Web/UI/JavaScript/JsNoCache.js | 16 ++++++++++++++++ .../UI/JavaScript/Resources.Designer.cs | 4 ++-- src/Umbraco.Web/UI/JavaScript/Resources.resx | 17 ++--------------- src/Umbraco.Web/Umbraco.Web.csproj | 1 + 6 files changed, 35 insertions(+), 30 deletions(-) create mode 100644 src/Umbraco.Web/UI/JavaScript/JsNoCache.js diff --git a/src/Umbraco.Web/Search/ExamineEvents.cs b/src/Umbraco.Web/Search/ExamineEvents.cs index a33fdb7b1b..5886f51e77 100644 --- a/src/Umbraco.Web/Search/ExamineEvents.cs +++ b/src/Umbraco.Web/Search/ExamineEvents.cs @@ -40,8 +40,7 @@ namespace Umbraco.Web.Search /// /// /// We need to do this on the Started event as to guarantee that all resolvers are setup properly. - /// - + /// protected override void ApplicationStarted(UmbracoApplicationBase httpApplication, ApplicationContext applicationContext) { LogHelper.Info("Initializing Examine and binding to business logic events"); @@ -334,8 +333,7 @@ namespace Umbraco.Web.Search )); } } - - [SecuritySafeCritical] + private static void ReIndexForMedia(IMedia sender, bool isMediaPublished) { ExamineManager.Instance.ReIndexNode( @@ -357,7 +355,6 @@ namespace Umbraco.Web.Search /// If true, indicates that we will only delete this item from indexes that don't support unpublished content. /// If false it will delete this from all indexes regardless. /// - [SecuritySafeCritical] private static void DeleteIndexForEntity(int entityId, bool keepIfUnpublished) { ExamineManager.Instance.DeleteFromIndex( @@ -378,7 +375,6 @@ namespace Umbraco.Web.Search /// /// Value indicating whether the item is published or not /// - [SecuritySafeCritical] private static void ReIndexForContent(IContent sender, bool isContentPublished) { ExamineManager.Instance.ReIndexNode( @@ -397,8 +393,7 @@ namespace Umbraco.Web.Search /// /// /// true if data is going to be returned from cache - /// - + /// [Obsolete("This method is no longer used and will be removed from the core in future versions, the cacheOnly parameter has no effect. Use the other ToXDocument overload instead")] public static XDocument ToXDocument(Content node, bool cacheOnly) { @@ -409,8 +404,7 @@ namespace Umbraco.Web.Search /// Converts a content node to Xml /// /// - /// - + /// private static XDocument ToXDocument(Content node) { if (TypeHelper.IsTypeAssignableFrom(node)) diff --git a/src/Umbraco.Web/UI/JavaScript/JsInitialization.cs b/src/Umbraco.Web/UI/JavaScript/JsInitialization.cs index f2ffd55f28..dd75780968 100644 --- a/src/Umbraco.Web/UI/JavaScript/JsInitialization.cs +++ b/src/Umbraco.Web/UI/JavaScript/JsInitialization.cs @@ -1,10 +1,14 @@ using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Text.RegularExpressions; using System.Web; using ClientDependency.Core; +using ClientDependency.Core.Config; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Umbraco.Core; +using Umbraco.Core.Configuration; using Umbraco.Core.IO; using Umbraco.Core.Manifest; using System.Linq; @@ -42,8 +46,6 @@ namespace Umbraco.Web.UI.JavaScript { var result = GetJavascriptInitializationArray(httpContext, umbracoInit, additionalJsFiles); var noCache = Resources.JsNoCache; - - //if debugging, add timestamp, if in production we tell yepNope to append umb+cdf version //this is needed even tho cdf does this on its serverside merged js @@ -52,7 +54,12 @@ namespace Umbraco.Web.UI.JavaScript noCache = noCache.Replace("##rnd##", "(new Date).getTime()"); else { - var version = "'" + Umbraco.Core.Configuration.UmbracoVersion.Current.ToString() + "." + ClientDependency.Core.Config.ClientDependencySettings.Instance.Version + "'"; + //create a unique hash code of the current umb version and the current cdf version + var versionHash = new HashCodeCombiner(); + versionHash.AddCaseInsensitiveString(UmbracoVersion.Current.ToString()); + versionHash.AddCaseInsensitiveString(ClientDependencySettings.Instance.Version.ToString(CultureInfo.InvariantCulture)); + + var version = "'" + versionHash.GetCombinedHashCode() + "'"; noCache = noCache.Replace("##rnd##", version); } diff --git a/src/Umbraco.Web/UI/JavaScript/JsNoCache.js b/src/Umbraco.Web/UI/JavaScript/JsNoCache.js new file mode 100644 index 0000000000..707c716778 --- /dev/null +++ b/src/Umbraco.Web/UI/JavaScript/JsNoCache.js @@ -0,0 +1,16 @@ +yepnope.addFilter(function (resourceObj) { + var url = resourceObj.url.toLowerCase(); + var rnd = ##rnd##; + var op = "?"; + debugger; + if(url.indexOf("lib/") === 0 || url.indexOf("js/umbraco.") === 0 || url.indexOf("dependencyhandler.axd") > 0) { + + return resourceObj; + } + if(url.indexOf("?") > 0){ + op = "&"; + } + + resourceObj.url = resourceObj.url + op + "umb__rnd=" + rnd; + return resourceObj; +}); \ No newline at end of file diff --git a/src/Umbraco.Web/UI/JavaScript/Resources.Designer.cs b/src/Umbraco.Web/UI/JavaScript/Resources.Designer.cs index 8c951ae2ff..626bd8d54d 100644 --- a/src/Umbraco.Web/UI/JavaScript/Resources.Designer.cs +++ b/src/Umbraco.Web/UI/JavaScript/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18444 +// Runtime Version:4.0.30319.34011 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -95,7 +95,7 @@ namespace Umbraco.Web.UI.JavaScript { /// return resourceObj; /// } /// if(url.indexOf("?") > 0){ - /// _op = "&"; + /// _op = "&"; /// } /// /// resourceObj.url = resourceObj.url + _op + "umb__rnd=" + rnd; diff --git a/src/Umbraco.Web/UI/JavaScript/Resources.resx b/src/Umbraco.Web/UI/JavaScript/Resources.resx index 035fe38089..3c99af3c60 100644 --- a/src/Umbraco.Web/UI/JavaScript/Resources.resx +++ b/src/Umbraco.Web/UI/JavaScript/Resources.resx @@ -121,21 +121,8 @@ jsinitialize.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - - yepnope.addFilter(function (resourceObj) { - var url = resourceObj.url; - var rnd = ##rnd##; - var _op = "?"; - if(url.indexOf("lib/") === 0 || url.indexOf("js/umbraco.") === 0){ - return resourceObj; - } - if(url.indexOf("?") > 0){ - _op = "&"; - } - - resourceObj.url = resourceObj.url + _op + "umb__rnd=" + rnd; - return resourceObj; -}); + + jsnocache.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 Main.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index afbb667a32..5969bee701 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -1829,6 +1829,7 @@ +