mwrock / RequestReduce

Instantly makes your .net website faster by reducing the number and size of requests with almost no effort.
www.requestreduce.org
Apache License 2.0
228 stars 48 forks source link

Split javascriptProcessingDisabled into 2 #176

Closed jsassner closed 12 years ago

jsassner commented 12 years ago

Hi. I'd like to see the possibilty to split the optionjavascriptProcessingDisabled into two: one that enables/disables minifying, and one to enable/disable combining. What i want to accomplish is to keep original javascript library authors minified javascript, but combine it into the RequestReduce destination file.

mwrock commented 12 years ago

Sorry for the delayed response. While I understand what you are asking for, I'm a bit unclear on your scenario. Are you saying you would like to keep the Javascript Unminified but have it bundled? Or vice versa? If its the first, its possible to accomplish that now. Let me know if this is what you want and I will reply with instructions. I'm also curious what the motivation is. I'm sure you have good reason, but I jut want to better understand the use case. Thanks!

jsassner commented 12 years ago

I'd like to have the javascript unmodified, but bundle it with all the other js scripts that RR minifies.

The reason i want this is i encountered some already minified scripts not working with RR (i used the un-minified versions from the original authors), but i guess this was more due to a "bug" in their un-minified code. It was many versions ago using RR, so it could also be that some bugs have been fixed in RR. If it's doable to have already minified scripts bundled, i'm a happy camper.

mwrock commented 12 years ago

I would try it again. There have been several minification bugs fixed by the MS Ajax Minifier which is what RR uses for minification. However, you can effectively turn off minification by using the RR API to supply your own minifier that basically does nothing.

Create a minifier like this:

    public class NonMinifier : Minifier
    {
        public new string Minify<T>(string unMinifiedContent) where T : IResourceType
        {
            if (typeof(T) == typeof(CssResource))
                return base.Minify<CssResource>(unMinifiedContent);
            if (typeof(T) == typeof(JavaScriptResource))
                return unMinifiedContent;

            throw new ArgumentException("Cannot Minify Resources of unknown type", "unMinifiedContent");
        }
    }

You would just need to add the following code to your startup code:

RequestReduce.Api.Registry.RegisterMinifier<NonMinifier>();
jsassner commented 12 years ago

This (https://ajaxmin.codeplex.com/workitem/17812) is the issue i had (and why i opened this ticket). Seems it's going to bed fixed soon.

I can't get the code above to work. When i install it, and do the "Registry.RegisterMinifier();" in Application_Start, and having a breakpoint in the NonMinifier class it's not hit. I guess it's due to me missing something. I use the 1.8.32 NuGet package.

mwrock commented 12 years ago

My Apologies. The current default Minifier Minify method is not virtual and declaring it as New in my example will not work. The next release due in the next week will have a virtual method you can override and will also include ajax min version 4.53 which may have your core fix.