Compressible Content-Type / mime checking utility for HTTP compression decisions
npx @tessl/cli install tessl/npm-compressible@2.0.0A utility library for determining whether HTTP Content-Type and MIME types are compressible. The package provides intelligent compression decisions by checking MIME types against the comprehensive mime-db database and applying fallback patterns for common compressible types.
npm install compressibleconst compressible = require('compressible');const compressible = require('compressible');
// Check various content types
console.log(compressible('text/html')); // => true
console.log(compressible('image/png')); // => false
console.log(compressible('application/json')); // => true
console.log(compressible('video/mp4')); // => false
// Handles Content-Type strings with parameters
console.log(compressible('text/html; charset=utf-8')); // => true
console.log(compressible('application/json; charset=utf-8')); // => true
// Case insensitive
console.log(compressible('TEXT/HTML')); // => true
console.log(compressible('Application/JSON')); // => true
// Unknown or uncertain types return undefined
console.log(compressible('application/x-unknown')); // => undefined
// Invalid input returns false
console.log(compressible(null)); // => false
console.log(compressible(undefined)); // => false
console.log(compressible(42)); // => falseThe compressible package follows a simple two-tier decision architecture:
undefined for uncertain cases rather than making assumptionsThis design ensures accurate compression decisions while providing predictable fallback behavior for edge cases.
Determines if a given MIME type or Content-Type string is suitable for HTTP compression algorithms like gzip or brotli.
/**
* Checks if a type is compressible.
*
* @param {string} type - MIME type or Content-Type string to check
* @returns {boolean|undefined} true if compressible, false if not compressible, undefined if uncertain
*/
function compressible(type)Parameters:
type (string): A MIME type (e.g., "text/html") or Content-Type string with parameters (e.g., "text/html; charset=utf-8")Returns:
true: The type is known to be compressiblefalse: The type is definitely not compressible, or the input is invalidundefined: The compressibility is uncertain (not explicitly defined in mime-db and doesn't match fallback patterns)Input Processing:
Compression Logic:
text/* types → true (e.g., text/html, text/plain, text/css)*/*+json types → true (e.g., application/hal+json)*/*+text types → true (e.g., application/something+text)*/*+xml types → true (e.g., application/soap+xml)undefined for types that don't match any patternError Handling:
falsefalseUsage Examples:
// Common web content types
compressible('text/html'); // => true
compressible('text/css'); // => true
compressible('text/javascript'); // => true
compressible('application/json'); // => true
compressible('application/xml'); // => true
// Images and media (typically not compressible)
compressible('image/jpeg'); // => false
compressible('image/png'); // => false
compressible('video/mp4'); // => false
compressible('audio/mpeg'); // => false
// Structured data formats
compressible('application/hal+json'); // => true
compressible('application/soap+xml'); // => true
compressible('application/rss+xml'); // => true
// Content-Type with parameters
compressible('text/html; charset=utf-8'); // => true
compressible('application/json; charset=utf-8'); // => true
// Unknown or custom types
compressible('application/x-custom'); // => undefined
compressible('custom/type'); // => undefined
// Invalid inputs
compressible(null); // => false
compressible(undefined); // => false
compressible(''); // => false
compressible(42); // => false