Leo He

How to enable response compression in ASP.Net Core

Enable both Gzip and Brotli compression.

Brotli compression has better performance when dealing HTML, CSS and JS files. you can enable it in the Startup.cs file.

// response compression
services.AddResponseCompression(options =>
{
    options.Providers.Add<BrotliCompressionProvider>();
    options.Providers.Add<GzipCompressionProvider>();
    // support custom mimetypes
    options.MimeTypes =
        ResponseCompressionDefaults.MimeTypes.Concat(
            new[] { "image/svg+xml" });
});

services.Configure<BrotliCompressionProviderOptions>(options =>
{
    options.Level = (CompressionLevel)4; // 4 or 5 is OK
});

Default Response Compression Mime Types

public static readonly IEnumerable<string> MimeTypes = new[]
{
	// General
	"text/plain",
	// Static files
	"text/css",
	"application/javascript",
	"text/javascript",
	// MVC
	"text/html",
	"application/xml",
	"text/xml",
	"application/json",
	"text/json",
	// WebAssembly
	"application/wasm",
};

ResponseCompressionDefaults

Use Response Compression

app.UseResponseCompression() in the Configure method needs to be before app.UseStaticFiles() as otherwise headers have already been sent.

app.UseResponseCompression();

Setting Brotli compression level when using response compression in ASP.NET Core

Markdown examples

Markdown support

Markdig is used as the Markdown processor and the following markdown features are enabled by default:

Tables

How to create the following table with styling, using pipe tables and generic attributes.

Company Contact Country
Alfreds Futterkiste Maria Anders Germany
Centro comercial Moctezuma Francisco Chang Mexico
Ernst Handel Roland Mendel Austria
Island Trading Helen Bennett UK
{.table .table-striped}
|Company|Contact|Country|
|-|-|-|
|Alfreds Futterkiste|Maria Anders|Germany|
|Centro comercial Moctezuma|Francisco Chang|Mexico|
|Ernst Handel|Roland Mendel|Austria|
|Island Trading|Helen Bennett|UK|

Using CSS

How to create the following blockquote with an bootstrap info-alert style, using generic attributes.

Normally the dangers inherent in the diverse hardware environment enhances the efficiency of the inductive associative dichotomy on a strictly limited basis.

{.alert .alert-info}
> Normally the dangers inherent in the diverse hardware environment enhances the efficiency of the inductive associative dichotomy on a strictly limited basis.

Resize Image

Resizing image is supported by Markdig, using below attribute syntax to resize an image.

![](http://example.com/image.jpg){width=250 height=120}