From ccfaebb09f99bd8bfe281a26ca8770a3758e9ec4 Mon Sep 17 00:00:00 2001 From: Elitsa Marinovska Date: Tue, 24 Mar 2020 17:34:34 +0100 Subject: [PATCH] More of the Smidge initial implementation. Adding TODOs for next steps --- src/Umbraco.Core/Assets/AssetFile.cs | 5 ++- src/Umbraco.Core/Assets/IAssetFile.cs | 2 +- .../Constants-RuntimeMinification.cs | 23 +++++++++++ src/Umbraco.Core/Runtime/IRuntimeMinifier.cs | 6 +-- ...oBackOfficeApplicationBuilderExtensions.cs | 25 ------------ ...coBackOfficeServiceCollectionExtensions.cs | 8 ++-- .../Smidge/SmidgeComponent.cs | 22 +++++++++++ .../Smidge/SmidgeComposer.cs | 18 +++++++++ .../Smidge/SmidgeRuntimeMinifier.cs | 39 +++++++++++++------ .../Umbraco.Web.BackOffice.csproj | 1 + src/Umbraco.Web.UI.NetCore/appsettings.json | 2 +- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 6 +++ .../Templates/EditProfile.cshtml | 13 +++++-- .../PartialViewMacros/Templates/Login.cshtml | 14 +++++-- .../Templates/RegisterMember.cshtml | 13 +++++-- .../Umbraco/Views/AuthorizeUpgrade.cshtml | 7 ++++ .../Umbraco/Views/Default.cshtml | 12 +++--- .../Umbraco/Views/Preview/Index.cshtml | 14 ++++--- .../CDF/ClientDependencyRuntimeMinifier.cs | 19 ++++++--- .../Mvc/MinifyJavaScriptResultAttribute.cs | 3 +- 20 files changed, 176 insertions(+), 76 deletions(-) create mode 100644 src/Umbraco.Core/Constants-RuntimeMinification.cs create mode 100644 src/Umbraco.Web.BackOffice/Smidge/SmidgeComponent.cs create mode 100644 src/Umbraco.Web.BackOffice/Smidge/SmidgeComposer.cs diff --git a/src/Umbraco.Core/Assets/AssetFile.cs b/src/Umbraco.Core/Assets/AssetFile.cs index d60e1824b8..9dd269a2a2 100644 --- a/src/Umbraco.Core/Assets/AssetFile.cs +++ b/src/Umbraco.Core/Assets/AssetFile.cs @@ -18,7 +18,7 @@ namespace Umbraco.Core.Assets public int Group { get; set; } public string PathNameAlias { get; set; } public string ForceProvider { get; set; } - public bool ForceBundle { get; set; } + public string Bundle { get; } /// /// Used to store additional attributes in the HTML markup for the item @@ -30,7 +30,7 @@ namespace Umbraco.Core.Assets #endregion - public AssetFile(AssetType type) + public AssetFile(AssetType type, string bundleName = "unspecfed") { DependencyType = type; HtmlAttributes = new Dictionary(); @@ -39,6 +39,7 @@ namespace Umbraco.Core.Assets Priority = 100; //Unless a group is specified, all dependencies will go into the same, default, group. Group = 100; + Bundle = bundleName; } } } diff --git a/src/Umbraco.Core/Assets/IAssetFile.cs b/src/Umbraco.Core/Assets/IAssetFile.cs index 03471890d6..da2558c845 100644 --- a/src/Umbraco.Core/Assets/IAssetFile.cs +++ b/src/Umbraco.Core/Assets/IAssetFile.cs @@ -10,7 +10,7 @@ namespace Umbraco.Core.Assets int Group { get; set; } string PathNameAlias { get; set; } string ForceProvider { get; set; } - bool ForceBundle { get; set; } + string Bundle { get; } IDictionary HtmlAttributes { get; } } } diff --git a/src/Umbraco.Core/Constants-RuntimeMinification.cs b/src/Umbraco.Core/Constants-RuntimeMinification.cs new file mode 100644 index 0000000000..be90b86003 --- /dev/null +++ b/src/Umbraco.Core/Constants-RuntimeMinification.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Umbraco.Core +{ + public static partial class Constants + { + public static class RuntimeMinification + { + public static class CssBundles + { + public const string Default = "default-css"; + public const string Index = "index-css"; + } + + public static class JsBundles + { + public const string Default = "default-js"; + } + } + } +} diff --git a/src/Umbraco.Core/Runtime/IRuntimeMinifier.cs b/src/Umbraco.Core/Runtime/IRuntimeMinifier.cs index a282293205..9af446a9c1 100644 --- a/src/Umbraco.Core/Runtime/IRuntimeMinifier.cs +++ b/src/Umbraco.Core/Runtime/IRuntimeMinifier.cs @@ -14,17 +14,17 @@ namespace Umbraco.Core.Runtime //return type IHtmlString //IClientDependencyPath[] - string RenderCssHere(params string[] path); + string RenderCssHere(string bundleName); // return type HtmlHelper string RequiresJs(string filePath); // return type IHtmlString - string RenderJsHere(); + string RenderJsHere(string bundleName); IEnumerable GetAssetPaths(AssetType assetType, List attributes); - string Minify(string src); + string Minify(string src, AssetType assetType); void Reset(); string GetScriptForBackOffice(); IEnumerable GetAssetList(); diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeApplicationBuilderExtensions.cs b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeApplicationBuilderExtensions.cs index d537759ba4..1f06a818d6 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeApplicationBuilderExtensions.cs +++ b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeApplicationBuilderExtensions.cs @@ -1,7 +1,5 @@ using System; using Microsoft.AspNetCore.Builder; -using Smidge; -using Smidge.Models; namespace Umbraco.Web.BackOffice.AspNetCore { @@ -14,29 +12,6 @@ namespace Umbraco.Web.BackOffice.AspNetCore throw new ArgumentNullException(nameof(app)); } - app.UseRuntimeMinifier(); - - return app; - } - - public static IApplicationBuilder UseRuntimeMinifier(this IApplicationBuilder app) - { - app.UseSmidge(bundles => - { - bundles.Create("default-css", - new CssFile("~/assets/css/umbraco.css"), - new CssFile("~/lib/bootstrap-social/bootstrap-social.css"), - new CssFile("~/lib/font-awesome/css/font-awesome.min.css")); - - bundles.Create("index-css", - new CssFile("assets/css/canvasdesigner.css")); - - bundles.Create("default-js", WebFileType.Js, - "//cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js", - "//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.min.js", - "//cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.min.js"); - }); - return app; } } diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs index 89f6b02c93..3da66ea06c 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs @@ -42,6 +42,7 @@ namespace Umbraco.Web.BackOffice.AspNetCore var httpContextAccessor = serviceProvider.GetService(); var webHostEnvironment = serviceProvider.GetService(); var hostApplicationLifetime = serviceProvider.GetService(); + var configuration = serviceProvider.GetService(); var configs = serviceProvider.GetService(); @@ -51,7 +52,7 @@ namespace Umbraco.Web.BackOffice.AspNetCore hostApplicationLifetime, configs); - services.AddRuntimeMinifier(); + services.AddRuntimeMinifier(configuration); return services; } @@ -84,9 +85,10 @@ namespace Umbraco.Web.BackOffice.AspNetCore return services; } - public static IServiceCollection AddRuntimeMinifier(this IServiceCollection services) + public static IServiceCollection AddRuntimeMinifier(this IServiceCollection services, + IConfiguration configuration) { - services.AddSmidge((IConfiguration) ConfigurationManager.GetSection("smidge")); + services.AddSmidge(configuration.GetSection("Umbraco:Smidge")); return services; } diff --git a/src/Umbraco.Web.BackOffice/Smidge/SmidgeComponent.cs b/src/Umbraco.Web.BackOffice/Smidge/SmidgeComponent.cs new file mode 100644 index 0000000000..1a3e4a75fa --- /dev/null +++ b/src/Umbraco.Web.BackOffice/Smidge/SmidgeComponent.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Umbraco.Core.Composing; +using Umbraco.Web.Runtime; + +namespace Umbraco.Web.BackOffice.Smidge +{ + [ComposeAfter(typeof(WebInitialComponent))] + public sealed class SmidgeComponent : IComponent + { + public void Initialize() + { + throw new NotImplementedException(); + } + + public void Terminate() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Umbraco.Web.BackOffice/Smidge/SmidgeComposer.cs b/src/Umbraco.Web.BackOffice/Smidge/SmidgeComposer.cs new file mode 100644 index 0000000000..61257a9a46 --- /dev/null +++ b/src/Umbraco.Web.BackOffice/Smidge/SmidgeComposer.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Umbraco.Core; +using Umbraco.Core.Composing; +using Umbraco.Core.Runtime; + +namespace Umbraco.Web.BackOffice.Smidge +{ + public sealed class SmidgeComposer : ComponentComposer + { + public override void Compose(Composition composition) + { + base.Compose(composition); + composition.RegisterUnique(); + } + } +} diff --git a/src/Umbraco.Web.BackOffice/Smidge/SmidgeRuntimeMinifier.cs b/src/Umbraco.Web.BackOffice/Smidge/SmidgeRuntimeMinifier.cs index e9565edbc4..aa4271509f 100644 --- a/src/Umbraco.Web.BackOffice/Smidge/SmidgeRuntimeMinifier.cs +++ b/src/Umbraco.Web.BackOffice/Smidge/SmidgeRuntimeMinifier.cs @@ -17,7 +17,9 @@ namespace Umbraco.Web.BackOffice.Smidge public class SmidgeRuntimeMinifier : IRuntimeMinifier { private readonly SmidgeHelper _smidge; - public string GetHashValue => new SmidgeConfig((IConfiguration) ConfigurationManager.GetSection("smidge")).Version; + + // TODO: We need to use IConfiguration to get the section (ConfigurationManager is not the way to do it) + public string GetHashValue => new SmidgeConfig((IConfiguration)ConfigurationManager.GetSection("Umbraco:Smidge")).Version; public SmidgeRuntimeMinifier(SmidgeHelper smidge) { @@ -28,9 +30,9 @@ namespace Umbraco.Web.BackOffice.Smidge throw new NotImplementedException(); } - public string RenderCssHere(params string[] path) + public string RenderCssHere(string bundleName) { - throw new NotImplementedException(); + return _smidge.CssHereAsync(bundleName).ToString(); } public string RequiresJs(string filePath) @@ -38,27 +40,42 @@ namespace Umbraco.Web.BackOffice.Smidge throw new NotImplementedException(); } - public string RenderJsHere() + public string RenderJsHere(string bundleName) { - throw new NotImplementedException(); + return _smidge.JsHereAsync(bundleName).ToString(); } public IEnumerable GetAssetPaths(AssetType assetType, List attributes) { - throw new NotImplementedException(); + var parsed = new List(); + + if (assetType == AssetType.Javascript) + attributes.ForEach(x => parsed.AddRange(_smidge.GenerateJsUrlsAsync(x.Bundle).Result)); + else + attributes.ForEach(x => parsed.AddRange(_smidge.GenerateCssUrlsAsync(x.Bundle).Result)); + + return parsed; } - public string Minify(string src) + public string Minify(string src, AssetType assetType) { - //TextReader reader = new StringReader(src); - // var jsMinifier = new NuglifyJs(); + if (assetType == AssetType.Javascript) + { - // return jsMinifier.ProcessAsync(); - return ""; + // TODO: use NuglifyJs to minify JS files (https://github.com/Shazwazza/Smidge/blob/master/src/Smidge.Nuglify/NuglifyJs.cs) + } + else + { + // TODO: use NuglifyCss to minify CSS files (https://github.com/Shazwazza/Smidge/blob/master/src/Smidge.Nuglify/NuglifyCss.cs) + } + + throw new NotImplementedException(); } public void Reset() { + // TODO: Need to figure out how to delete temp directories to make sure we get fresh caches + throw new NotImplementedException(); } diff --git a/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj b/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj index 81a8b4809a..a7ca2a93d6 100644 --- a/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj +++ b/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj @@ -19,6 +19,7 @@ + diff --git a/src/Umbraco.Web.UI.NetCore/appsettings.json b/src/Umbraco.Web.UI.NetCore/appsettings.json index 11f10cc1db..4ac9d4c0c4 100644 --- a/src/Umbraco.Web.UI.NetCore/appsettings.json +++ b/src/Umbraco.Web.UI.NetCore/appsettings.json @@ -85,7 +85,7 @@ ] } }, - "smidge": { + "Smidge": { "dataFolder" : "App_Data/Smidge", "version" : "1" } diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index fe11a8d9aa..8ca4ae1188 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -62,6 +62,9 @@ + + ..\..\..\..\.nuget\packages\smidge\3.1.0\lib\netcoreapp3.0\Smidge.dll + @@ -108,6 +111,9 @@ runtime; build; native; contentfiles; analyzers all + + 3.1.0 + diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/EditProfile.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/EditProfile.cshtml index 5f75f8d792..f4a0441cf5 100644 --- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/EditProfile.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/EditProfile.cshtml @@ -1,5 +1,7 @@ @using System.Web.Mvc.Html @using ClientDependency.Core.Mvc +@using Smidge +@using Umbraco.Core @using Umbraco.Web @using Umbraco.Web.Composing @using Umbraco.Web.Controllers @@ -10,15 +12,18 @@ Html.EnableClientValidation(); Html.EnableUnobtrusiveJavaScript(); - Html.RequiresJs("https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"); - Html.RequiresJs("https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.min.js"); - Html.RequiresJs("https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.min.js"); + + SmidgeHelper + .CreateJsBundle(Constants.RuntimeMinification.JsBundles.Default) + .RequiresJs("//cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js") + .RequiresJs("//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.min.js") + .RequiresJs("//cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.min.js"); var success = TempData["ProfileUpdateSuccess"] != null; } @*NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed*@ -@Html.RenderJsHere() +@Current.RuntimeMinifier.RenderJsHere("default-js") @if (Current.MembershipHelper.IsLoggedIn() && profileModel != null) { diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/Login.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/Login.cshtml index a7effa5606..87fdec00be 100644 --- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/Login.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/Login.cshtml @@ -1,6 +1,9 @@ @using System.Web.Mvc.Html @using ClientDependency.Core.Mvc +@using Smidge @using Umbraco.Web +@using Umbraco.Core +@using Umbraco.Web.Composing @using Umbraco.Web.Models @using Umbraco.Web.Controllers @inherits Umbraco.Web.Macros.PartialViewMacroPage @@ -11,13 +14,16 @@ Html.EnableClientValidation(); Html.EnableUnobtrusiveJavaScript(); - Html.RequiresJs("https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"); - Html.RequiresJs("https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.min.js"); - Html.RequiresJs("https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.min.js"); + + SmidgeHelper + .CreateJsBundle(Constants.RuntimeMinification.JsBundles.Default) + .RequiresJs("//cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js") + .RequiresJs("//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.min.js") + .RequiresJs("//cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.min.js"); } @* NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed *@ -@Html.RenderJsHere() +@Current.RuntimeMinifier.RenderJsHere("default-js") @using (Html.BeginUmbracoForm("HandleLogin")) { diff --git a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/RegisterMember.cshtml b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/RegisterMember.cshtml index 81389f4a3d..b7cbfeafe4 100644 --- a/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/RegisterMember.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/PartialViewMacros/Templates/RegisterMember.cshtml @@ -1,5 +1,7 @@ @using System.Web.Mvc.Html @using ClientDependency.Core.Mvc +@using Smidge +@using Umbraco.Core @using Umbraco.Web @using Umbraco.Web.Composing @using Umbraco.Web.Controllers @@ -34,15 +36,18 @@ Html.EnableClientValidation(); Html.EnableUnobtrusiveJavaScript(); - Html.RequiresJs("https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"); - Html.RequiresJs("https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.min.js"); - Html.RequiresJs("https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.min.js"); + + SmidgeHelper + .CreateJsBundle(Constants.RuntimeMinification.JsBundles.Default) + .RequiresJs("//cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js") + .RequiresJs("//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.min.js") + .RequiresJs("//cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.min.js"); var success = TempData["FormSuccess"] != null; } @*NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed*@ -@Html.RenderJsHere() +@Current.RuntimeMinifier.RenderJsHere("default-js") @if (success) { diff --git a/src/Umbraco.Web.UI/Umbraco/Views/AuthorizeUpgrade.cshtml b/src/Umbraco.Web.UI/Umbraco/Views/AuthorizeUpgrade.cshtml index 1039e4e14c..234f674419 100644 --- a/src/Umbraco.Web.UI/Umbraco/Views/AuthorizeUpgrade.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/Views/AuthorizeUpgrade.cshtml @@ -1,8 +1,11 @@ @using Umbraco.Core @using ClientDependency.Core @using ClientDependency.Core.Mvc +@using Smidge @using Umbraco.Web.Composing @using Umbraco.Web +@using Constants = Umbraco.Core.Constants +using Umbraco.Core @inherits System.Web.Mvc.WebViewPage @{ Layout = null; @@ -11,6 +14,10 @@ .RequiresCss("assets/css/umbraco.css", "Umbraco") .RequiresCss("lib/bootstrap-social/bootstrap-social.css", "Umbraco") .RequiresCss("lib/font-awesome/css/font-awesome.min.css", "Umbraco"); + + SmidgeHelper + .CreateCssBundle(Constants.RuntimeMinification.CssBundles.Index) + .RequiresCss("~/assets/css/canvasdesigner.css"); } diff --git a/src/Umbraco.Web.UI/Umbraco/Views/Default.cshtml b/src/Umbraco.Web.UI/Umbraco/Views/Default.cshtml index da5770cddd..c981fef6c1 100644 --- a/src/Umbraco.Web.UI/Umbraco/Views/Default.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/Views/Default.cshtml @@ -1,8 +1,10 @@ @using Umbraco.Core @using ClientDependency.Core @using ClientDependency.Core.Mvc +@using Smidge @using Umbraco.Web.Composing @using Umbraco.Web +@using Constants = Umbraco.Core.Constants @inherits WebViewPage @@ -18,10 +20,9 @@ } } - Html - .RequiresCss("assets/css/umbraco.css", "Umbraco") - .RequiresCss("lib/bootstrap-social/bootstrap-social.css", "Umbraco") - .RequiresCss("lib/font-awesome/css/font-awesome.min.css", "Umbraco"); + SmidgeHelper + .CreateCssBundle(Constants.RuntimeMinification.CssBundles.Default) + .RequiresCss("~/assets/css/umbraco.css", "~/lib/bootstrap-social/bootstrap-social.css", "~/lib/font-awesome/css/font-awesome.min.css"); } @@ -38,8 +39,7 @@ Umbraco - @Html.RenderCssHere( - new BasicPath("Umbraco", Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoPath))) + @Current.RuntimeMinifier.RenderCssHere("default-css") diff --git a/src/Umbraco.Web.UI/Umbraco/Views/Preview/Index.cshtml b/src/Umbraco.Web.UI/Umbraco/Views/Preview/Index.cshtml index e46ae58096..586216ec56 100644 --- a/src/Umbraco.Web.UI/Umbraco/Views/Preview/Index.cshtml +++ b/src/Umbraco.Web.UI/Umbraco/Views/Preview/Index.cshtml @@ -1,14 +1,18 @@ -@using Umbraco.Core +@using Umbraco.Core @using ClientDependency.Core @using ClientDependency.Core.Mvc +@using Smidge @using Umbraco.Web.Composing @using Umbraco.Web +@using Constants = Umbraco.Core.Constants @inherits System.Web.Mvc.WebViewPage @{ var disableDevicePreview = Model.DisableDevicePreview.ToString().ToLowerInvariant(); - Html.RequiresCss("assets/css/canvasdesigner.css", "Umbraco"); + SmidgeHelper + .CreateCssBundle(Constants.RuntimeMinification.CssBundles.Index) + .RequiresCss("~/assets/css/canvasdesigner.css"); } @@ -18,8 +22,7 @@ - @Html.RenderCssHere( - new BasicPath("Umbraco", Current.IOHelper.ResolveUrl(Current.Configs.Global().UmbracoPath))) + @Current.RuntimeMinifier.RenderCssHere("index-css") @@ -64,7 +67,8 @@ } - diff --git a/src/Umbraco.Web/JavaScript/CDF/ClientDependencyRuntimeMinifier.cs b/src/Umbraco.Web/JavaScript/CDF/ClientDependencyRuntimeMinifier.cs index 44f0d4b757..676a0a5702 100644 --- a/src/Umbraco.Web/JavaScript/CDF/ClientDependencyRuntimeMinifier.cs +++ b/src/Umbraco.Web/JavaScript/CDF/ClientDependencyRuntimeMinifier.cs @@ -45,7 +45,7 @@ namespace Umbraco.Web.JavaScript.CDF //return html; } - public string RenderCssHere(params string[] path) + public string RenderCssHere(string bundleName) { throw new NotImplementedException(); //return new HtmlString(_htmlHelper.ViewContext.GetLoader().RenderPlaceholder( @@ -59,7 +59,7 @@ namespace Umbraco.Web.JavaScript.CDF //return _htmlHelper; } - public string RenderJsHere() + public string RenderJsHere(string bundleName) { throw new NotImplementedException(); //return new HtmlString( @@ -75,7 +75,7 @@ namespace Umbraco.Web.JavaScript.CDF foreach (var assetFile in attributes) { - if(!((AssetFile)assetFile is null)) + if (!((AssetFile)assetFile is null)) dependencies.Add(MapAssetFile(assetFile)); } @@ -86,12 +86,19 @@ namespace Umbraco.Web.JavaScript.CDF return toParse.Split(new[] { DependencyPathRenderer.Delimiter }, StringSplitOptions.RemoveEmptyEntries); } - public string Minify(string src) + public string Minify(string src, AssetType assetType) { TextReader reader = new StringReader(src); - var jsMinifier = new JSMin(); - return jsMinifier.Minify(reader); + if (assetType == AssetType.Javascript) + { + var jsMinifier = new JSMin(); + return jsMinifier.Minify(reader); + } + + // asset type is Css + var cssMinifier = new CssMinifier(); + return cssMinifier.Minify(reader); } public void Reset() diff --git a/src/Umbraco.Web/Mvc/MinifyJavaScriptResultAttribute.cs b/src/Umbraco.Web/Mvc/MinifyJavaScriptResultAttribute.cs index fa1e041d85..a4fb38a625 100644 --- a/src/Umbraco.Web/Mvc/MinifyJavaScriptResultAttribute.cs +++ b/src/Umbraco.Web/Mvc/MinifyJavaScriptResultAttribute.cs @@ -1,4 +1,5 @@ using System.Web.Mvc; +using Umbraco.Core.Assets; using Umbraco.Web.Composing; using Umbraco.Core.Hosting; using Umbraco.Core.Runtime; @@ -43,7 +44,7 @@ namespace Umbraco.Web.Mvc //minify the result var result = jsResult.Script; - var minified = _runtimeMinifier.Minify(result); + var minified = _runtimeMinifier.Minify(result, AssetType.Javascript); jsResult.Script = minified; } }