如何用Microsoft.AspNetCore.ResponseCompression压缩所有响应。

问题描述 投票:0回答:1
  1. 为什么Microsoft.AspNetCore.ResponseCompression不压缩所有响应?
  2. 如果添加大量的mime-types会不会有问题?
  3. 是否有任何库有mime-type常量列表?
c# asp.net asp.net-core-2.1
1个回答
0
投票

看上去没有压缩所有响应的选项,所以我用常见的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",
    };
}
© www.soinside.com 2019 - 2024. All rights reserved.