【发布时间】:2020-05-12 14:41:08
【问题描述】:
- 为什么 Microsoft.AspNetCore.ResponseCompression 不压缩所有响应?
- 如果添加很多 mime-types 会有什么问题吗?
- 是否有任何具有 mime 类型常量列表的库?
【问题讨论】:
标签: c# asp.net asp.net-core-2.1
【问题讨论】:
标签: c# asp.net asp.net-core-2.1
看起来没有压缩所有响应的选项,所以我创建了具有常见 mime 类型的集合
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",
};
}
【讨论】: