Skip to content

ASP.NET Extensions

Andrey Taritsyn edited this page Aug 21, 2015 · 15 revisions

Prior to WebMarkupMin version 2.0, configuring of ASP.NET extensions were made by using the Web.config file. Now during configuration instead of the declarative approach (using the configuration file) is used in the imperative approach (using the program code).

The rejection of the declarative approach was due to the following reasons:

  1. Microsoft for several years, uses an imperative approach for configuration of individual parts of ASP.NET (for example, Web API or Web Optimization Framework).
  2. ASP.NET 5 no longer supports the Web.config files.

Extensions for ASP.NET 4.X and ASP.NET 5 use different configuration models. In ASP.NET 4.X configuring of extensions are made through special classes: WebMarkupMinConfiguration, HtmlMinificationManager, XhtmlMinificationManager and XmlMinificationManager. In ASP.NET 5 configuration of extension is based on the Options framework and using the following classes: WebMarkupMinOptions, HtmlMinificationOptions, XhtmlMinificationOptions and XmlMinificationOptions. However, these configuration models have a lot in common.

WebMarkupMin сommon configuration

WebMarkupMinConfiguration and WebMarkupMinOptions classes inherit WebMarkupMinConfigurationBase class, which has the following properties:

Property name Data type Default value Description
DisableMinification Boolean false Flag for whether to disable markup minification.
DisableCompression Boolean false Flag for whether to disable HTTP compression of content.
MaxResponseSize Int32 -1 Maximum size of the response (in bytes), in excess of which disables the minification of markup. If this property is set equal to -1, then checking of the response size is not performed.
DisablePoweredByHttpHeaders Boolean false Flag for whether to disable the *-Minification-Powered-By HTTP headers (e.g. X-HTML-Minification-Powered-By: WebMarkupMin)

Markup minification managers and options

All classes of markup minification managers and options have IncludedPages and ExcludedPages properties, that allow to include/exclude site pages from processing by corresponding markup minifier. These properties are of type IList<IUrlMatcher>, and by default contains the empty lists, i.e. by default filtering is disabled.

There are 3 built-in implementations of IUrlMatcher interface:

  1. ExactUrlMatcher. As a pattern used the URL (e.g., new ExactUrlMatcher("/contact")).
  2. RegexUrlMatcher. As a pattern used a ECMAScript standard compliant regular expression (e.g., new RegexUrlMatcher(@"^/minifiers/x(?:ht)?ml-minifier$")).
  3. WildcardUrlMatcher. Used a pattern, that supports Wildcard syntax (e.g., new WildcardUrlMatcher("/minifiers/x*ml-minifier")). This syntax supports 2 special characters: * (match any number of any characters) and ? (match exactly one character).

By default all of the above implementations of IUrlMatcher interface during matching is not case-sensitive. To change this behavior you need to pass to constructor of class as the second parameter value equals to true (e.g., new ExactUrlMatcher("/Contact", true)).

HTML minification manager and options

HtmlMinificationManager and HtmlMinificationOptions classes have the following common properties:

	<tr valign="top">
		<td><code>CssMinifierFactory</code></td>
		<td><code title="WebMarkupMin.Core.ICssMinifierFactory">ICssMinifierFactory</code></td>
		<td>Instance of <code title="WebMarkupMin.Core.KristensenCssMinifierFactory">KristensenCssMinifierFactory</code> class</td>
		<td>
			CSS minifier factory.
		</td>
	</tr>
	<tr valign="top">
		<td><code>JsMinifierFactory</code></td>
		<td><code title="WebMarkupMin.Core.IJsMinifierFactory">IJsMinifierFactory</code></td>
		<td>Instance of <code title="WebMarkupMin.Core.CrockfordJsMinifierFactory">CrockfordJsMinifierFactory</code> class</td>
		<td>
			JS minifier factory.
		</td>
	</tr>
</tbody>
Property name Data type Default value Description
MinificationSettings HtmlMinificationSettings Instance of HtmlMinificationSettings class HTML minification settings.
SupportedMediaTypes ISet<string> text/html List of supported media types.
IncludedPages IList<IUrlMatcher> Empty list List of URL matchers, which is used to include pages to processing by HTML minifier.
ExcludedPages IList<IUrlMatcher> Empty list List of URL matchers, which is used to exclude pages from processing by HTML minifier.

XHTML minification manager and options

XhtmlMinificationManager and XhtmlMinificationOptions classes have the following common properties:

Property name Data type Default value Description
MinificationSettings XhtmlMinificationSettings Instance of XhtmlMinificationSettings class XHTML minification settings.
SupportedMediaTypes ISet<string> text/html, application/xhtml+xml List of supported media types.
IncludedPages IList<IUrlMatcher> Empty list List of URL matchers, which is used to include pages to processing by XHTML minifier.
ExcludedPages IList<IUrlMatcher> Empty list List of URL matchers, which is used to exclude pages from processing by XHTML minifier.
CssMinifierFactory ICssMinifierFactory Instance of KristensenCssMinifierFactory class CSS minifier factory.
JsMinifierFactory IJsMinifierFactory Instance of CrockfordJsMinifierFactory class JS minifier factory.

XML minification manager and options

XmlMinificationManager and XmlMinificationOptions classes have the following common properties:

Property name Data type Default value Description
MinificationSettings XmlMinificationSettings Instance of XmlMinificationSettings class XML minification settings.
SupportedMediaTypes ISet<string> application/xml, text/xml, application/xml-dtd, application/xslt+xml, application/rss+xml, application/atom+xml, application/rdf+xml, application/soap+xml, application/wsdl+xml, image/svg+xml, application/mathml+xml, application/voicexml+xml, application/srgs+xml List of supported media types.
IncludedPages IList<IUrlMatcher> Empty list List of URL matchers, which is used to include pages to processing by XML minifier.
ExcludedPages IList<IUrlMatcher> Empty list List of URL matchers, which is used to exclude pages from processing by XML minifier.