How to disable js minify at nop4.5

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 anno tempo fa
In Nop.Web.Framework.UI.NopHtmlHelper, on line 569, remove ".MinifyCss()".
From:
 var asset = GetOrCreateBundle(item.Src, (bundleKey, assetFiles) =>
                {
                    return _assetPipeline.AddBundle(bundleKey, $"{MimeTypes.TextCss}; charset=UTF-8", assetFiles)
                        .EnforceFileExtensions(".css")
                        .AdjustRelativePaths()
                        .Concatenate()
                        .AddResponseHeader(HeaderNames.XContentTypeOptions, "nosniff")
                        .MinifyCss();
                });

to
 var asset = GetOrCreateBundle(item.Src, (bundleKey, assetFiles) =>
                {
                    return _assetPipeline.AddBundle(bundleKey, $"{MimeTypes.TextCss}; charset=UTF-8", assetFiles)
                        .EnforceFileExtensions(".css")
                        .AdjustRelativePaths()
                        .Concatenate()
                        .AddResponseHeader(HeaderNames.XContentTypeOptions, "nosniff");
                });

Css files will be minified only when bundled.
1 anno tempo fa
I could not find this MinifyCss() method in nop 4.6 develop version.
is there any simple setting that is coming up  in nop 4.6 version?
What lines of code , I need to comment in nop 4.6 develop version?
Due to this error , debugging is  very difficult.

Thanks ,
Sateesh
1 anno tempo fa
mumsateesh wrote:
I could not find this MinifyCss() method in nop 4.6 develop version.
is there any simple setting that is coming up  in nop 4.6 version?
What lines of code , I need to comment in nop 4.6 develop version?
Due to this error , debugging is  very difficult.

Thanks ,
Sateesh


Now, you can avoid a calling of the Uglify.Css method here: https://github.com/nopSolutions/nopCommerce/blob/develop/src/Presentation/Nop.Web.Framework/WebOptimizer/Processors/NopCssMinifier.cs#L37
1 anno tempo fa
Another to your issue is to not rely on nopCommerces minification. Instead, use your own bundler and place your static javascript in your theme, and have your own build step for those files. This way you can use webpack or a similar tool and let that handle your minification/bundling process, in my opinion it's much more flexible and gives better results. You can also do other stuff like brotli compression in webpack which would require a plugin in nopcommerce.
1 anno tempo fa
Hi guys,
Found this trick to disable Javascript minification in nop 4.5*. Settings do not work because of bug in AssetPipelineExtensions:

        public static IAsset AddJavaScriptBundle(this IAssetPipeline pipeline, string route, params string[] sourceFiles)
        {
            return pipeline.AddJavaScriptBundle(route, new CodeSettings(), sourceFiles);
        }

As you see it creates IAsset instance with default settings and minify set to true regardless any config.

I've modified NopHtmlHelper.cs (line 386) to remove WebOptimizer.JavaScriptMinifier in development mode from the list of available processors.

var asset = GetOrCreateBundle(item.Src, _assetPipeline.AddJavaScriptBundle);

                if (_webHostEnvironment.IsDevelopment())
                {
                    var jsMinifier = asset.Processors
                        .FirstOrDefault(p => p.GetType().FullName == "WebOptimizer.JavaScriptMinifier");

                    if (jsMinifier != null)
                    {
                        asset.Processors.Remove(jsMinifier);
                    }
                }

                result.AppendFormat("<script type=\"{0}\" src=\"{1}?v={2}\"></script>",
                    MimeTypes.TextJavascript, asset.Route, asset.GenerateCacheKey(_actionContextAccessor.ActionContext.HttpContext));
1 anno tempo fa
chashikNop wrote:
Hi guys,
Found this trick to disable Javascript minification in nop 4.5*. Settings do not work because of bug in AssetPipelineExtensions:

        public static IAsset AddJavaScriptBundle(this IAssetPipeline pipeline, string route, params string[] sourceFiles)
        {
            return pipeline.AddJavaScriptBundle(route, new CodeSettings(), sourceFiles);
        }

As you see it creates IAsset instance with default settings and minify set to true regardless any config.

I've modified NopHtmlHelper.cs (line 386) to remove WebOptimizer.JavaScriptMinifier in development mode from the list of available processors.

var asset = GetOrCreateBundle(item.Src, _assetPipeline.AddJavaScriptBundle);

                if (_webHostEnvironment.IsDevelopment())
                {
                    var jsMinifier = asset.Processors
                        .FirstOrDefault(p => p.GetType().FullName == "WebOptimizer.JavaScriptMinifier");

                    if (jsMinifier != null)
                    {
                        asset.Processors.Remove(jsMinifier);
                    }
                }

                result.AppendFormat("<script type=\"{0}\" src=\"{1}?v={2}\"></script>",
                    MimeTypes.TextJavascript, asset.Route, asset.GenerateCacheKey(_actionContextAccessor.ActionContext.HttpContext));


Didn't work for me on version 4.5..
This property "Processors" seems to not exist, and the property "_assetPipeline.Assets" is readonly...
I'm still trying to get those javascripts not minified to debug a javascript behavior of onepagecheckout step, duplicating my script if I hit back button and then next button a couple times...
1 anno tempo fa
iphoda_coelho wrote:
Hi guys,
Found this trick to disable Javascript minification in nop 4.5*. Settings do not work because of bug in AssetPipelineExtensions:

        public static IAsset AddJavaScriptBundle(this IAssetPipeline pipeline, string route, params string[] sourceFiles)
        {
            return pipeline.AddJavaScriptBundle(route, new CodeSettings(), sourceFiles);
        }

As you see it creates IAsset instance with default settings and minify set to true regardless any config.

I've modified NopHtmlHelper.cs (line 386) to remove WebOptimizer.JavaScriptMinifier in development mode from the list of available processors.

var asset = GetOrCreateBundle(item.Src, _assetPipeline.AddJavaScriptBundle);

                if (_webHostEnvironment.IsDevelopment())
                {
                    var jsMinifier = asset.Processors
                        .FirstOrDefault(p => p.GetType().FullName == "WebOptimizer.JavaScriptMinifier");

                    if (jsMinifier != null)
                    {
                        asset.Processors.Remove(jsMinifier);
                    }
                }

                result.AppendFormat("<script type=\"{0}\" src=\"{1}?v={2}\"></script>",
                    MimeTypes.TextJavascript, asset.Route, asset.GenerateCacheKey(_actionContextAccessor.ActionContext.HttpContext));


Didn't work for me on version 4.5..
This property "Processors" seems to not exist, and the property "_assetPipeline.Assets" is readonly...
I'm still trying to get those javascripts not minified to debug a javascript behavior of onepagecheckout step, duplicating my script if I hit back button and then next button a couple times...


https://1drv.ms/u/s!AghLRh3xrCQxgcs6M-smSYn7_-VeDQ?e=c2PK63
Here is my NopHtmlHelper.cs file.
You can use F12 (Go to Definition) method to find everything you need.
Or you can just compile and use my version :)
1 anno tempo fa
Did anyone find a solution to this at nop 4.60? None of the above is working for me. My JS files are not bundled, but are still minified.
1 anno tempo fa
paravan3010 wrote:
Did anyone find a solution to this at nop 4.60? None of the above is working for me. My JS files are not bundled, but are still minified.





private IAsset CreateJavaScriptAsset(string bundleKey, string[] assetFiles)
        {
            var asset = _assetPipeline.AddBundle(bundleKey, $"{MimeTypes.TextJavascript}; charset=UTF-8", assetFiles)
                        .EnforceFileExtensions(".js", ".es5", ".es6")
                        .AddResponseHeader(HeaderNames.XContentTypeOptions, "nosniff");

            //to more precisely log problem files we minify them before concatenating
            asset.Processors.Add(new NopJsMinifier());

            asset.Concatenate();

            return asset;
        }


Hello, paravan3010,
You can apply workaround from the couple of my previous posts here.

P. S. for moderators: can not attach images to a post
1 anno tempo fa
Hi chashikNop,
thanks for your reply! Unfortunatelly this didn't help me either. All JS files are still requested and loaded minified.
I also believe this issue deserves more attention from the nopCommerce team regardless of whether the workaround works.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.