A mime-db equivalent to serve data for each entry separately over CDN. Enables small, selective download for any given query.
npm install mime-db-cdnš A mime-db equivalent that lets you download just the data you need via multiple CDNs. Unlike mime-db, one no more needs to download the entire database file at once.
š Mirrors the complete mime-db database, including the unofficial MIME-types (prs., x-, vnd.*).
š Additionally includes file-extension => MIME-type(s) reverse lookup data, with the MIME-types sorted in descending order of importance.
š Also offers a portable JavaScript SDK (ESM) to access the database through dynamic imports, providing memory-efficiency for both browsers and server-side runtimes.
mime-db directly, therefore, entails downloading the entire database at once, albeit from a CDN. If you just need to query a handful of MIME-types or file-extensions, downloading the entire database followed by loading and retaining it in memory would be an overkill. This problem persists with popular packages based on mime-db, such as mime or mime-types, which, in order to function, must first store the entire database locally on the user's machine.The current project solves this problem by fragmenting mime-db into tiny JSON files, each storing data only for one of the available MIME-types or file-extensions. To understand the file-structure, explore the directories in the database branch. Each of these JSON files is readily downloadable using any of the free CDNs that serve GitHub or npm contents, e.g.
- jsdelivr
- statically
- raw.githack
- unpkg
curl or wget in Linux,Fetch API in JavaScript etc..š For the JS-SDK usage, see the SDK section below.
š below refers to either
- database, i.e. the database branch, or
- , i.e. any of the tags listed here, latest being the topmost one. See versioning for more details.
š For simplicity, only 2 CDNs (jsdelivr and unpkg) are explicitly mentioned. It is trivial to construct similar URLs for other available CDNs.
From jsdelivr,
```
https://cdn.jsdelivr.net/gh/somajitdey/mime-db-cdn@/mime-types/
``
https://cdn.jsdelivr.net/npm/mime-db-cdn@
From unpkg,
``
https://unpkg.com/mime-db-cdn@
Above, replace with your chosen MIME-type e.g. image/jpeg.
š Apart from an extensions array, the JSON for a MIME-type also contains these relevant data. See examples below.
From jsdelivr,
``
https://cdn.jsdelivr.net/gh/somajitdey/mime-db-cdn@/extensions/
``
https://cdn.jsdelivr.net/npm/mime-db-cdn@
From unpkg,
``
https://unpkg.com/mime-db-cdn@
Above, replace with your chosen extension e.g. jpg.
š The JSON contains an array of mimeTypes. Note that this array of MIME-types is sorted in descending order of importance according to the same logic used by mime-types. See examples below. If only one MIME-type is required, simply choose the first element from the array!
From jsdelivr,
``
https://cdn.jsdelivr.net/gh/somajitdey/mime-db-cdn@/file-types/type.
``
https://cdn.jsdelivr.net/npm/mime-db-cdn@
From unpkg,
``
https://unpkg.com/mime-db-cdn@
Content-Type header received for a GET request to the above URLs might contain the desired MIME-type, as provided by the CDN provider.
š The above links also return the actual MIME-types as text in the response body. For extensions shared by multiple MIME-types, one MIME-type is listed per line. Note that these MIME-types are not sorted in any particular order. If a sorted list is required, download the JSON.
release, from which our database is built, is always recorded as a semver pre-release.Format:
For example, our version 4.0.0-1.54.0 is equivalent to the
mime-db release v1.54.0.$3
Just click on any of the links in this section.š Data for
image/jpeg from mime-db release v1.54.0 =>https://cdn.jsdelivr.net/gh/somajitdey/mime-db-cdn@4.0.0-1.54.0/mime-types/image/jpeg/data.json
š MIME-type(s) for file-extension
exe=>https://unpkg.com/mime-db-cdn@4.0.0-1.54.0/extensions/exe/data.json
š Proper
Content-Type for file-extensions json and png =>https://unpkg.com/mime-db-cdn@4.0.0-1.54.0/file-types/type.json
https://unpkg.com/mime-db-cdn@4.0.0-1.54.0/file-types/type.png
JavaScript SDK
Our JS-SDK is designed to be memory-efficient regardless of how big the original MIME-type database ever becomes. This is acheived through dynamic imports, viz. importing data as and when needed.
For browsers, this means more requests to the CDNs in return for low memory footprint. Thanks to caching by the browsers, however, the increased CDN requests might ultimately be a non-issue.
For server-side runtimes like Node, dynamically importing tiny JSONs avoids complexities of reading and parsing a huge JSON database using streams.
$3
For browsers:
`html
`For Node.js:
Install as
`bash
npm install mime-db-cdn
`Import as
`javascript
import { mimeToExtensions, extensionToMimes } from 'mime-db-cdn';
`$3
#### mimeToExtensions(mimeType)
Returns a promise that fulfills with an array of file-extensions.mimeTypeString representing a MIME-type with structure:
`
type/subtypetype/subtype;parameter=value
`The returned promise is rejected with
Not Found error if the provided mimeType is unavailable in mime-db.Examples:
`javascript
console.log(await mimeToExtensions('application/mp4'));
// Prints [ 'mp4', 'mpg4', 'mp4s', 'm4p' ]console.log(await mimeToExtensions('application/javascript; charset=utf-8'));
// Prints [ 'js' ]
`#### extensionToMimes(
extension)
Returns a promise that fulfills with an array of MIME-types.extensionString representing either of
- path, e.g.
dir/subdir/file.ext
- file-extension with or without the leading dot, e.g. mp4, .mp4
- file-name, e.g. file.mp4, file.version.1.2.0.mp4The returned promise is rejected with
Not Found error if the provided mimeType is unavailable in mime-db.Examples:
`javascript
console.log(await extensionToMimes('dir/subdir/path.version.js'));console.log(await extensionToMimes('js'));
console.log(await extensionToMimes('.js'));
// Prints [ 'application/javascript', 'text/javascript' ]
``If you like this project, you can show your appreciation by
- giving it a star ā
- sponsoring me through š

Thank you š.