How to bundle .css and .js using System.Web.Optimization?
Hello everyone.
I want to be able to use @Scripts.Render("~/Script/js") and @Styles.Render("~/Content/css")
After some research i came up with this.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Optimization;
using Umbraco.Core;
namespace MySolution.App_Code
{
public class CustomEventHandler : IApplicationEventHandler
{
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
RegisterStyles(BundleTable.Bundles);
RegisterJavascript(BundleTable.Bundles);
}
private static void RegisterStyles(BundleCollection bundles)
{
bundles.Add(new StyleBundle("~/Content/styles").Include(
"~/css/*.css"
)
);
}
private static void RegisterJavascript(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/Script/js").Include(
"~/scripts/jquery/*.js"
)
);
}
}
}
1) Now System.Web.Optimization couldn't be found.
2) Then i used : PM> Install-Package Microsoft.AspNet.Web.Optimization
3) Now i got no errors in my built. BUT...
4) Then i got a Newtonsoft.Json assembly error referance.
WRN : Logging assemblybinding is disabled .
Logging assemblybindingserror activated by setting the registry value [ HKLM \ Software \ Microsoft \ Fusion ! EnableLog ] ( DWORD ) at 1.
Note The performance impaired by logging assemblybindingserror .
This function is disabled by removing the registry value [ HKLM \ Software \ Microsoft \ Fusion ! EnableLog ] .
I prefer to be able to make my own simple bundle code ;-)
Regards Bo
Edited:
After a whole day trying to sholve the problem. My Umbraco Build now has 100 warnings and 2 errors. So my feelings for umbraco is at a very low place.
But i got the Logging assemblybindingserror activated. Its just told me that there was 2 assembly referances of Newtonsoft.Json. But i could only find one.
How to bundle .css and .js using System.Web.Optimization?
Hello everyone.
I want to be able to use @Scripts.Render("~/Script/js") and @Styles.Render("~/Content/css")
After some research i came up with this.
1) Now System.Web.Optimization couldn't be found.
2) Then i used : PM> Install-Package Microsoft.AspNet.Web.Optimization
3) Now i got no errors in my built. BUT...
4) Then i got a Newtonsoft.Json assembly error referance.
I hope someone can help.
Not a real answer for your question but I Bad really good experience using Optimus package for bundling of CSS and JS files.
Maybe that helps.
Regards David
I prefer to be able to make my own simple bundle code ;-)
Regards Bo
Edited: After a whole day trying to sholve the problem. My Umbraco Build now has 100 warnings and 2 errors. So my feelings for umbraco is at a very low place.
But i got the Logging assemblybindingserror activated. Its just told me that there was 2 assembly referances of Newtonsoft.Json. But i could only find one.
I finally managed to get it to work.
Now you can use @Scripts.Render() and @Styles.Render in your .cshtml file.
Adding Bundles Directly
Taken from step 4 in my former reply.
This time add a class file called BundleConfig.cs
Now find your AssemblyInfo.cs. Its under Solution -> Properties -> AssemblyInfo.cs.
Now you can use @Scripts.Render() and @Styles.Render in your .cshtml file.
Other info here http://churchley.net/blog/2015/bundling-minifying-umbraco-fanoe-starter-kit/ and here https://gist.github.com/jkarsrud/5143239
using Umbraco.Core;
using System.Web.Optimization; namespace Anturaz_new.EventHandlers { public class RegisterBundlesHandler: Umbraco.Core.ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase
umbracoApplication, ApplicationContext applicationContext) { BundleConfig.RegisterBundles(BundleTable.Bundles); }
}
is working on a reply...