Search code examples
c#asp.netasp.net-core-2.1

How to compress all responses with Microsoft.AspNetCore.ResponseCompression


  1. Why Microsoft.AspNetCore.ResponseCompression don't compress all responses?
  2. Will be any problems if add lot of mime-types?
  3. Is there any libs with mime-types constant lists?

Solution

  • Look like there is no option to compress all responses, so I create collection with common mime types

    services.AddResponseCompression(options => { options.MimeTypes = MimeTypes.CommonMimeTypes; });
    
    internal static class MimeTypes
    {
        public static readonly IEnumerable<string> CommonMimeTypes = new[]
        {
            "application/javascript",
            "application/json",
            "application/ld+json",
            "application/msword",
            "application/octet-stream",
            "application/ogg",
            "application/pdf",
            "application/rtf",
            "application/vnd.apple.installer+xml",
            "application/vnd.mozilla.xul+xml",
            "application/vnd.ms-excel",
            "application/vnd.ms-fontobject",
            "application/vnd.ms-powerpoint",
            "application/vnd.oasis.opendocument.presentation",
            "application/vnd.oasis.opendocument.spreadsheet",
            "application/vnd.oasis.opendocument.text",
            "application/vnd.openxmlformats-officedocument.presentationml.presentation",
            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
            "application/vnd.visio",
            "application/x-csh",
            "application/x-sh",
            "application/x-shockwave-flash",
            "application/xhtml+xml",
            "application/xml",
            "audio/3gpp",
            "audio/3gpp2",
            "audio/aac",
            "audio/midi",
            "audio/x-midi",
            "audio/mpeg",
            "audio/ogg",
            "audio/opus",
            "audio/wav",
            "audio/webm",
            "font/otf",
            "font/ttf",
            "font/woff",
            "font/woff2",
            "image/bmp",
            "image/gif",
            "image/jpeg",
            "image/png",
            "image/svg+xml",
            "image/tiff",
            "image/vnd.microsoft.icon",
            "image/webp",
            "text/calendar",
            "text/css",
            "text/csv",
            "text/html",
            "text/javascript",
            "text/json",
            "text/plain",
            "text/xml",
            "video/3gpp",
            "video/3gpp2",
            "video/mp2t",
            "video/mpeg",
            "video/ogg",
            "video/webm",
            "video/x-msvideo",
        };
    }