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
440 stars 48 forks source link

Question regarding asp.net webforms > .ascx #165

Closed VincentVanHulstPersonal closed 7 months ago

VincentVanHulstPersonal commented 7 months ago

Hello, i was wondering if it would be possible to also minify the content of the html output rendered through .ascx controls? I have some .aspx pages with placeholders that load .ascx files on page init. The output of the .aspx page is minified/compressed but not the contents of the .ascx files.

Taritsyn commented 7 months ago

Hello, Vincent!

Quite non-standard functionality, similar to a CMS. I definitely haven't tested such things.

There are two ways to solve this problem:

  1. Use the WebMarkupMin.AspNet4.HttpModules module instead of the WebMarkupMin.AspNet4.WebForms module.
  2. Try to reproduce this error in the form of demo project and send me a link to it. Then I'll see how I can fix this problem.
Taritsyn commented 7 months ago

HTML output of the following code is completely minified:

protected void Page_Init(object sender, EventArgs e)
{
    var myControl = this.LoadControl("~/Controls/MyControl.ascx") as MyControl;
    myPlaceholder.Controls.Add(myControl);
}
VincentVanHulstPersonal commented 7 months ago

Thank you for this feedback. I will dive into this again. Only other thing that i can think of is that we have some nested .ascx loading. (index.aspx > main.ascx > overview.ascx).

VincentVanHulstPersonal commented 7 months ago

Furthermore I have index.aspx > Inherits WebMarkupMin.AspNet4.WebForms.MinifiedAndCompressedHtmlPage The .ascx's just inherit > System.Web.UI.UserControl Is that correct?

Taritsyn commented 7 months ago

Yes, this is correct.

Taritsyn commented 7 months ago

Does the .ascx file contain the pre and textarea tags, or ignoring comment tags?

VincentVanHulstPersonal commented 7 months ago

Ok i think for now we can close this issue; i now see some html parsing errors in de logger. Probably that is the issue. Regarding your question: we do have textarea tags.

VincentVanHulstPersonal commented 7 months ago

Yes problem solved; i found invalid markup in some CMS-content. Thank you for your help.

Taritsyn commented 7 months ago

Content of tags listed above is never minified.

I recommend you to write your own logger or use the built-in logger (ThrowExceptionLogger class). If you use ASP.NET Web Forms, then the logger for WebMarkupMin needs to be registered in the App_Start/WebMarkupMinConfig.cs file as follows:

using WebMarkupMin.Core.Loggers;
…
DefaultLogger.Current = new ThrowExceptionLogger();