Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using WebOptimizer and pre-minimized files?

If I am using the WebOptimizer -- https://github.com/ligershark/WebOptimizer -- for bundling and minification in my ASP.Net Core application is there any need to keep the minified versions of the client-side libraries that are being used around?

For example, do I still need code like this in the layout page:

<environment include="Development">
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
</environment>
<environment exclude="Development">
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
</environment>

Or can I just have the link to the un-minified version and WebOptimizer will minify it on the fly and then I can delete the boostrap.min.css file from my project?

And on a related note, what would the WebOptimizer middleware do if it encountered a pre-minified file?

like image 488
Christopher King Avatar asked Nov 05 '25 10:11

Christopher King


1 Answers

This is a bit old but I thought it was good to answer this.

Instead of doing it on the HTML part of things, you could configure the bundle to minify the file or not in your configuration, and just reference bootstrap.css in your html normally.

Here you can find an example of how this is done: https://www.vinayjadav.com/posts/bundle-js-css-aspnet-core

   public static class WebOptimizerBootstrapper
   {
       public static void Configure(ServiceRegistry services)
       {
           string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
           bool isDevelopment = environment == Environments.Development;
           services.AddWebOptimizer(pipeline =>
           {
               pipeline.AddCssBundle("/css/site.css", "css/**/*css");
               pipeline.AddJavaScriptBundle("/js/site.js", "js/**/*.js");
               if (!isDevelopment)
               {
                   pipeline.MinifyCssFiles();
                   pipeline.MinifyJsFiles();
               }
           });
       }
   }

And in your Program.cs (for .net core)

builder.Services.AddWebOptimizer(services=>WebOptimizerBootstraper.Configure)
like image 108
Oscar Avatar answered Nov 07 '25 15:11

Oscar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!