trullock / NUglify

NUglify is a HTML, JavaScript and CSS minification Library for .NET (fork of AjaxMin + new features)
Other
396 stars 79 forks source link

XML minification #310

Open mattscotty opened 2 years ago

mattscotty commented 2 years ago

XML minification can help by removing whitespace. However on testing using the HTML minifier, tags do not retain their case sensitivity and there is no option to do so (there is for the attributes).

The suggestion is to add an XML mode, e.g. Uglify.Xml() (as we have HTML, JS and CSS) and / or the ability to keep the case of tags within HTML.

trullock commented 2 years ago

This can probably be achieved with some tweaking of how the current HTML settings works - and maybe some new options as you suggest.

We'd need to go down the current behaviour and decide which things it should/shouldnt do by default and then what options are appropriate

mattscotty commented 2 years ago

Agree, my initial test used the following;

Uglify.Html(File.ReadAllText(xmlFile.FullName), new NUglify.Html.HtmlSettings
{
    RemoveAttributeQuotes = false,
    RemoveOptionalTags = false
}).Code

The main issue I encountered was that tag names were converted to lower case with no way to disable this, though other testing would obviously be required.

There are possible performance settings that may be on by default too, e.g.;

  //No JS or CSS should be present so can be disabled for performance(?)
  MinifyJs = false, 
  MinifyCss = false,

For the moment I've had to revert to another solution, but my preference would to be consistent and use Nuglify if we can tweak it a little.

For context, I did a test on a 646KB XML file and using the alternative solution, this was brought down to ~521KB, so a worthwhile saving. My Nuglify test was around that mark too (though with lower case tags, which my third party app was not able to handle).

trullock commented 2 years ago

Make a separate issue to control tag Name and attribute lowercasing and we'll address that first

mattscotty commented 2 years ago

Done; Add ability to disable tags being converted to lower case in HtmlSettings

Thanks

trullock commented 2 years ago

Note that NUglify wont lower-case tag names if they have an XML namespace