Skip to content

perf: reduce bundle size #154

@aladdin-add

Description

@aladdin-add

Proposal: Reduce bundle size by providing separate ESM/CJS packages and other optimizations

Description

First, thank you for developing and maintaining esquery! It's an incredibly useful library that's widely used across the JavaScript ecosystem. 🙏

Given its popularity and substantial download volume, I believe optimizing the package size would benefit the entire community. Smaller bundle sizes mean faster downloads, especially in regions with poor network connectivity, and reduced overall footprint for applications using esquery.

Current Situation Analysis

The current package appears to include multiple module formats (ESM, CJS, etc.) in a single package, which means all users download everything regardless of their specific module system requirements.

Image

Proposed Solutions

1. Split into Multiple Packages

Instead of bundling all module formats together, consider providing separate packages:

  • esquery (main package with ESM as primary)
  • esquery/cjs (CJS-specific version)

2. Remove pre-compressed *.min.js files​ from the distribution package.

All modern build tools (Webpack, Rollup, Vite, etc.) and bundlers have built-in, highly efficient compression capabilities (using Terser or similar). They can automatically generate optimized .min.js files during the user's application build process . Shipping these files within the esquery package is redundant and increases the package size unnecessarily.

Expected Benefits

  • Reduced Download Size: Users only download what they actually need for their specific environment
  • Better Performance: Faster installation times across the ecosystem
  • Modern Ecosystem Alignment: Follows current best practices for JavaScript package distribution

Additional Context

This optimization would be largely backward-compatible since it primarily affects how the package is structured and delivered rather than its API.

I'd be happy to send a PR if you are interested in. 🙌

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions