Skip to content

Commit

Permalink
replaced with set of AWS MIME types
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanchase committed Dec 19, 2022
1 parent 3cb1219 commit 539d8ea
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions src/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,57 @@ function isTextMime(mimeType: string) {
return /text|javascript|json|xml/.test(mimeType);
}

const COMPRESSIBLE_MIMES_RE =
/atom|css|eot|htc|html|ico|js|json|mjs|otf|rss|svg|text|ttf|webmanifest|xml/;
// Reference list of compressible MIME types from AWS
// https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html#compressed-content-cloudfront-file-types
const COMPRESSIBLE_MIMES_RE = new Set([
"application/dash+xml",
"application/eot",
"application/font",
"application/font-sfnt",
"application/javascript",
"application/json",
"application/opentype",
"application/otf",
"application/pkcs7-mime",
"application/protobuf",
"application/rss+xml",
"application/truetype",
"application/ttf",
"application/vnd.apple.mpegurl",
"application/vnd.mapbox-vector-tile",
"application/vnd.ms-fontobject",
"application/xhtml+xml",
"application/xml",
"application/x-font-opentype",
"application/x-font-truetype",
"application/x-font-ttf",
"application/x-httpd-cgi",
"application/x-javascript",
"application/x-mpegurl",
"application/x-opentype",
"application/x-otf",
"application/x-perl",
"application/x-ttf",
"font/eot",
"font/opentype",
"font/otf",
"font/ttf",
"image/svg+xml",
"text/css",
"text/csv",
"text/html",
"text/javascript",
"text/js",
"text/plain",
"text/richtext",
"text/tab-separated-values",
"text/xml",
"text/x-component",
"text/x-java-source",
"text/x-script",
"vnd.apple.mpegurl"
]);

function isCompressableMime(mimeType: string) {
return COMPRESSIBLE_MIMES_RE.test(mimeType);
return COMPRESSIBLE_MIMES_RE.has(mimeType);
}

0 comments on commit 539d8ea

Please sign in to comment.