Taritsyn / WebMarkupMin

The Web Markup Minifier (abbreviated WebMarkupMin) - a .NET library that contains a set of markup minifiers. The objective of this project is to improve the performance of web applications by reducing the size of HTML, XHTML and XML code.
Apache License 2.0
449 stars 48 forks source link

No minify anything #141

Closed ignaciosalazarcalle closed 2 years ago

ignaciosalazarcalle commented 2 years ago

Hello,

I'm trying use minify JS and CSS files but I don't get it. Steps:

  1. Create a new web asp.net core project 3.1
  2. Install WebMarkupMin.AspNetCore3
  3. Add this code

    
    public void ConfigureServices(IServiceCollection services)
    {
    // Add response caching service.
    services.AddResponseCaching();
    
    // Add WebMarkupMin services to the services container.
    services.AddWebMarkupMin(options =>
        {
            options.AllowMinificationInDevelopmentEnvironment = true;
            options.AllowCompressionInDevelopmentEnvironment = true;
        })
        .AddHtmlMinification(options =>
        {
            HtmlMinificationSettings settings = options.MinificationSettings;
            settings.RemoveRedundantAttributes = true;
            settings.RemoveHttpProtocolFromAttributes = true;
            settings.RemoveHttpsProtocolFromAttributes = true;
        })
        .AddHttpCompression(options =>
        {
            options.CompressorFactories = new List<ICompressorFactory>
            {
                //new BuiltInBrotliCompressorFactory(new BuiltInBrotliCompressionSettings
                //{
                //    Level = CompressionLevel.Fastest
                //}),
                new DeflateCompressorFactory(new DeflateCompressionSettings
                {
                    Level = CompressionLevel.Fastest
                }),
                new GZipCompressorFactory(new GZipCompressionSettings
                {
                    Level = CompressionLevel.Fastest
                })
            };
        });
    
    services.AddRazorPages();
    }

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); }

app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();
app.UseResponseCaching();

app.UseWebMarkupMin();

app.UseEndpoints(endpoints =>
{
    endpoints.MapRazorPages();
});

}



When I start the App the css and js files aren't minified.
What am I doing wrong?

Regards, 
Taritsyn commented 2 years ago

Hello, Ignacio!

WebMarkupMin can only minify a JS and CSS code embedded (script and style tags) and inlined (style attributes, event attributes and hyperlinks with javascript: protocol) in markup. To minify a JS and CSS files, use some kind of bundler (for example, Smidge).

WebMarkupMin can apply HTTP compression to a JS and CSS files, but this is just a side functionality. It is better to work with such files exclusively through bundler.

ignaciosalazarcalle commented 2 years ago

Hello, Ignacio!

WebMarkupMin can only minify a JS and CSS code embedded (script and style tags) and inlined (style attributes, event attributes and hyperlinks with javascript: protocol) in markup. To minify a JS and CSS files, use some kind of bundler (for example, Smidge).

WebMarkupMin can apply HTTP compression to a JS and CSS files, but this is just a side functionality. It is better to work with such files exclusively through bundler.

Understood, @Taritsyn .

Thanks for the information.