如何使用 Microsoft.AspNetCore.ResponseCompression 压缩所有响应
How to compress all responses with Microsoft.AspNetCore.ResponseCompression
- 为什么 Microsoft.AspNetCore.ResponseCompression 不压缩所有响应?
- 添加很多mime类型会不会有问题?
- 是否有任何带有 mime 类型常量列表的库?
看起来没有压缩所有回复的选项,所以我创建了包含常见 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",
};
}
- 为什么 Microsoft.AspNetCore.ResponseCompression 不压缩所有响应?
- 添加很多mime类型会不会有问题?
- 是否有任何带有 mime 类型常量列表的库?
看起来没有压缩所有回复的选项,所以我创建了包含常见 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",
};
}