Advice for integrating YUI .NET into a ASP.NET Web App

Apr 8, 2013 at 8:29 PM
Hi,

I am considering using this library within a .NET 4.0 ASP.NET Web forms App. None of the sample videos cover this specifically. So I've a few questions on this...
  • Can this package actually be integrated into a Web Forms web app instead of MVC App?
  • Are there any resources that can show me how to do this via either MsBuild or some other manner?
  • Apart from css/js within the web app I have server-side webcontrols that have css/js included with them as webResource files. I am considering removing the embedded resources and moving the css/js into the web app so that they would be processed by YUI. Would you consider this a good idea or is there a way for YUI .NET to handle the embedded resouces?
Thanks

Andy
Coordinator
Apr 9, 2013 at 3:23 AM
Hi Andy,

it's been years since I've touched WebForms (all MVC myself). I believe it can be used in a Web forms app because there's no MVC specific stuff at all.

1) and 2)

I've made a a video about to use MSBuild to leverage the compressor. Yes, the video is using an MVC project but that's irrelevant because it's using NOTHING MVC-special. U can copy the entire video and substitute the 1 sec in it where i do FILE=>NEW=>MVC with FILE=>NEW=>WebForms.

all the rest is the same.


3) Embedded resources .. hmm. never thought of that. If you're going to embedd the css/js, you can always manually minify the content and then just stick that result into the web resource? It's a PITA but a possible solution. Other than that, i would keep that content separate as u suggested.

GL!
Apr 9, 2013 at 8:08 AM
Hi GL,

Thanks for the reply. I had previously watched all your short clips (very informative) but just wanted to be sure that it was possible to integrate with Web forms.
I think I will seperate the CSS/JS with regards to the embedded resources as the DLLs are not used outside of the web app and so the need for embedding is removed.

Thanks!

Andy
Coordinator
Apr 9, 2013 at 8:10 AM
Hi Andy,

Agree with PK on 1 & 2.
As well as the msbuild video, if you go to the Source Code tab and navigate to Documentation/Post-build Events WebSite Example, this is an MVC project which uses msbuild and compresses your files when in Release mode. If you download and run the project, one of the pages on the site will discuss it in some detail.

re: Embedded resources - I thought about this before, replacing the resources post-build with minified versions, but you can't rewrite them in the assembly, so I abandoned that idea. Recently however, I have come up with another idea....though it is untested as yet so may need a tweak:

Lets say you have a file called myjs.js which is currently an embedded resource. Do the following:
  • Change it's build action to None
  • Create a copy of it called myjs.min.js and set the build action on that to be Embedded Resource
  • Whereever you would have referred to myjs.js, you need to replace with references to myjs.min.js
  • Create a pre build event (similar to the post build events example I mentioned earlier) which will, in Debug mode, just copy myjs.js as myjs.min.js (to ensure you always have the latest version) but in Release mode will minify myjs.js to myjs.min.js
The end result should be your embedded minified (or no minified) resource file.

hth!