Web Optimization Framework not rendering correctly
Hello,
This question isn't completly Umbraco related, but I rather ask my questions here than on SO. I'm using Bundling and Minification with the Web Optimization Framework and somehow it doesn't render. It's an Umbraco 4.7.2 website and I register the bundles at the same place I register events. Here is a piece of the code:
using System.Web.Optimization;
public class SiteApplicationBase : ApplicationBase
{
public SiteApplicationBase() {
RegisterStyles(BundleTable.Bundles);
RegisterJavascript(BundleTable.Bundles);
Document.BeforePublish += new Document.PublishEventHandler(Document_BeforePublish);
}
private static void RegisterStyles(BundleCollection bundles)
{
//Add all style files. These will be bundled and minified.
//After everything has been bundled (which only happens when debug=false in the web.config) check if there are no errors in the bundled file. Not all files can be bundled.
bundles.Add(new StyleBundle("~/bundle/styles.css").Include(
"~/css/main.css"
)
);
}
private static void RegisterJavascript(BundleCollection bundles)
{
//Add all javascript files. These will be bundled and minified.
//After everything has been bundled (which only happens when debug=false in the web.config) check if there are no errors in the bundled file. Not all files can be bundled.
bundles.Add(new ScriptBundle("~/bundle/javascript.js").Include(
"~/scripts/script1.js",
"~/scripts/script2.js"
)
);
}
It doesn't matter if bundling is enabled or disabled it always points to the path I'm using in Razor. Anyone know what could be the problem? I have it working on other websites where I create the bundles in OnApplicationStarted with the IApplicationEventHandler interface, but Umbraco 4.7.2 doesn't have that yet.
It might be because you are using .js and .css in your actual bundle names? Not sure if that confuses things but you might try calling it just "~/bundle/javascript"
Worth a try anyway... that's the only thing that jumped out at me as different from how I've used it.
Ok, I've never had issues with Umbraco and bundle names without .js/.css though, so can't cooperate on that.
Originally I thought that perhaps the .js/.css extensions in the bundle names would make the bundle handlers ignore them. But if it doesn't work without extensions as well, then it sounds like the handlers aren't wired up at all.
As you said yourself, perhaps you need to register the bundle config somewhere else than ApplicationBase.
Let us know here if you solve it yourself, otherwise I'll have a look at it later.
Web Optimization Framework not rendering correctly
Hello,
This question isn't completly Umbraco related, but I rather ask my questions here than on SO. I'm using Bundling and Minification with the Web Optimization Framework and somehow it doesn't render. It's an Umbraco 4.7.2 website and I register the bundles at the same place I register events. Here is a piece of the code:
After that I try to show the bundle with Razor:
So I expect that the HTML rendered would be this:
But instead it outputs this:
It doesn't matter if bundling is enabled or disabled it always points to the path I'm using in Razor. Anyone know what could be the problem? I have it working on other websites where I create the bundles in OnApplicationStarted with the IApplicationEventHandler interface, but Umbraco 4.7.2 doesn't have that yet.
Jeroen
It might be because you are using .js and .css in your actual bundle names? Not sure if that confuses things but you might try calling it just "~/bundle/javascript"
Worth a try anyway... that's the only thing that jumped out at me as different from how I've used it.
Andy
+1 to Andy's suggestion.
You can read here why I added .js and .css: https://twitter.com/j_breuer/status/367198864820158464
I tried it without the extension, but it's the same problem. Maybe I need to register them somewhere else instead of ApplicationBase.
Jeroen
Ok, I've never had issues with Umbraco and bundle names without .js/.css though, so can't cooperate on that.
Originally I thought that perhaps the .js/.css extensions in the bundle names would make the bundle handlers ignore them. But if it doesn't work without extensions as well, then it sounds like the handlers aren't wired up at all.
As you said yourself, perhaps you need to register the bundle config somewhere else than ApplicationBase.
Let us know here if you solve it yourself, otherwise I'll have a look at it later.
Cheers
You could try to register the bundle config on Application_Start as so:
Let me know if that helps at all :)
Cheers
is working on a reply...