-
Notifications
You must be signed in to change notification settings - Fork 48
XHTML Minifier
Taritsyn edited this page Aug 6, 2024
·
17 revisions
XHTML Minifier produces minification of HTML and XHTML code. As a result of minification on the output we get code, that follows the rules of XHTML.
Work with the XHTML Minifier is very similar to working with the HTML Minifier, only difference is that instead of the HtmlMinifier
and HtmlMinificationSettings
classes need to use the XhtmlMinifier
and XhtmlMinificationSettings
.
Let's consider in detail properties of the XhtmlMinificationSettings
class:
Property name | Data type | Default value | Description |
---|---|---|---|
WhitespaceMinificationMode |
WhitespaceMinificationMode enumeration |
Medium |
Whitespace minification mode. Can take the following values:
|
PreserveNewLines |
Boolean |
false |
Flag for whether to collapse whitespace to one newline string when whitespace contains a newline. |
NewLineStyle |
NewLineStyle enumeration |
Auto |
Style of the newline. Can take the following values:
|
RemoveHtmlComments |
Boolean |
true |
Flag for whether to remove all HTML comments, except conditional, noindex, KnockoutJS containerless comments, AngularJS 1.X comment directives, React DOM component comments and Blazor markers. |
PreservableHtmlCommentList |
String |
Empty string |
Comma-separated list of string representations of simple regular expressions, that define what HTML comments can not be removed (e.g. "/^\s*saved from url=\(\d+\)/i, /^\/?\$$/, /^[\[\]]$/" ).
Simple regular expressions somewhat similar to the ECMAScript regular expression literals. There are two varieties of the simple regular expressions:
|
RemoveHtmlCommentsFromScriptsAndStyles |
Boolean |
true |
Flag for whether to remove HTML comments from script and style tags.
|
UseShortDoctype |
Boolean |
false |
Flag for whether to replace existing document type declaration by short declaration - <!DOCTYPE html> .
|
UseMetaCharsetTag |
Boolean |
false |
Flag for whether to replace <meta http-equiv="content-type" content="text/html; charset=…" /> tag by <meta charset="…" /> tag
|
RenderEmptyTagsWithSpace |
Boolean |
true |
Flag for whether to allow the inserting space before slash in empty tags (for example, true - <br /> ; false - <br/> ).
|
RemoveTagsWithoutContent |
Boolean |
false |
Flag for whether to remove tags without content, except for textarea , tr , th and td tags, and tags with class , id , name , role , src and custom attributes.
|
AttributeQuotesStyle |
HtmlAttributeQuotesStyle enumeration |
Auto |
Style of the HTML attribute quotes. Can take the following values:
|
RemoveEmptyAttributes |
Boolean |
true |
Flag for whether to remove attributes, which have empty value (valid attributes are: class , id , name , style , title , lang , event attributes, action attribute of form tag and value attribute of input tag).
|
RemoveRedundantAttributes |
Boolean |
false |
Flag for whether to remove redundant attributes:
|
PreservableAttributeList |
String |
Empty string |
Comma-separated list of string representations of attribute expressions, that define what attributes can not be removed (e.g. "form[method=get i], input[type], [xmlns]" ).
Attribute expressions somewhat similar to the CSS Attribute Selectors. There are six varieties of the attribute expressions:
|
RemoveHttpProtocolFromAttributes |
Boolean |
false |
Flag for whether to remove the HTTP protocol portion (http: ) from URI-based attributes (tags marked with rel="external" are skipped).
|
RemoveHttpsProtocolFromAttributes |
Boolean |
false |
Flag for whether to remove the HTTPS protocol portion (https: ) from URI-based attributes (tags marked with rel="external" are skipped).
|
RemoveJsProtocolFromAttributes |
Boolean |
true |
Flag for whether to remove the javascript: pseudo-protocol portion from event attributes.
|
MinifyEmbeddedCssCode |
Boolean |
true |
Flag for whether to minify CSS code in style tags.
|
MinifyInlineCssCode |
Boolean |
true |
Flag for whether to minify CSS code in style attributes.
|
MinifyEmbeddedJsCode |
Boolean |
true |
Flag for whether to minify JS code in script tags.
|
MinifyInlineJsCode |
Boolean |
true |
Flag for whether to minify JS code in event attributes and hyperlinks with javascript: pseudo-protocol.
|
MinifyEmbeddedJsonData |
Boolean |
true |
Flag for whether to minify JSON data in script tags with application/json , application/ld+json , importmap and speculationrules types.
|
ProcessableScriptTypeList |
String |
"text/html" |
Comma-separated list of types of script tags, that are processed by minifier (e.g. "text/html, text/ng-template" ). Currently only supported the KnockoutJS, Kendo UI MVVM and AngularJS 1.X views.
|
MinifyKnockoutBindingExpressions |
Boolean |
false |
Flag for whether to minify the KnockoutJS binding expressions in data-bind attributes and containerless comments.
|
MinifyAngularBindingExpressions |
Boolean |
false |
Flag for whether to minify the AngularJS 1.X binding expressions in Mustache-style tags ({{}} ) and directives.
|
CustomAngularDirectiveList |
String |
Empty string |
Comma-separated list of names of custom AngularJS 1.X directives (e.g. "myDir, btfCarousel" ), that contain expressions. If value of the MinifyAngularBindingExpressions property equal to true , then the expressions in custom directives will be minified.
|
- Core
- External JS and CSS minifiers
- ASP.NET Extensions
- How to upgrade applications to version 2.X
- Additional reading and resources