Skip to content

Reduce bundle size to <0.7.x levels #127

Open
@mxdvl

Description

@mxdvl

Is your feature request related to a problem? Please describe.

Currently, the minified bundle size of version 2.1.2 of this package (44KB) is more than twice as big as the raw production build of React 19 (16KB). While it is an extremely useful package, it seems unfortunate that it ships so much code (~80%) that consists of MIME type information.

Describe the solution you'd like

Enable consumers to provide their known file types. Possibly export the ones from this package as a convenience. See #56 (comment)

Describe alternatives you've considered

Be much smarter about how MIME type information is encoded to reduce bundle size, using Regular Expressions for format variations, For example:

const BEFORE = new Map([
    // […]
    ['cb7', 'application/x-cbr'],
    ['cba', 'application/x-cbr'],
    ['cbr', 'application/x-cbr'],
    ['cbt', 'application/x-cbr'],
    ['cbz', 'application/x-cbr'],`
    // […]
]);

const AFTER = new Map([
    // […]
    [/cb[7artz]/i, 'application/x-cbr'],
    // […]
]);

This feels somewhat onerous and prone to errors. It will probably not reduce the file type significantly enough to be worthwhile.

We could consider whether to use file-type which only sits at 7KB for binary file formats rather than relying on the extension.

Additional context

How are the COMMON_FILE_TYPES decided? Is is sourced from Wikipedia? Is there a threshold for adding a new filetype? Should there be a criteria of prevalence for a file type to make it into file-selector?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions