# core-js — Standard JavaScript Polyfill Library > A modular standard library for JavaScript that provides polyfills for ECMAScript features, enabling modern code to run in older environments. ## Install Save as a script file and run: # core-js — Standard JavaScript Polyfill Library ## Quick Use ```bash # Install npm install core-js # Import all polyfills import "core-js"; # Or import only what you need import "core-js/actual/array/flat-map"; import "core-js/actual/promise"; import "core-js/actual/structured-clone"; ``` ## Introduction core-js is the most widely used JavaScript polyfill library, providing implementations of ECMAScript standard features for environments that do not natively support them. It powers the polyfill pipeline of Babel and is depended on by millions of npm packages. ## What core-js Does - Polyfills ECMAScript 2015 through 2024+ features (Promise, Symbol, Array methods, etc.) - Provides web platform API polyfills (structuredClone, URL, URLSearchParams) - Supports granular imports so applications only bundle needed polyfills - Integrates with Babel via @babel/preset-env for automatic polyfill injection - Supplies both global and pure (no-global-pollution) entry points ## Architecture Overview core-js is organized as a monorepo with the main polyfill package, a pure version that avoids modifying global prototypes, a compatibility data package, and a Babel integration helper. Each polyfill module is self-contained with its own dependency chain, allowing bundlers to tree-shake unused code when importing from specific paths. ## Self-Hosting & Configuration - Install core-js and configure Babel preset-env with useBuiltIns: "usage" or "entry" - Use core-js-pure for library authors who must avoid global prototype modification - Pin to a specific core-js major version to prevent unexpected behavior changes - Check core-js-compat for per-feature browser support data - Bundle size is controlled by importing only specific modules rather than the full library ## Key Features - Covers virtually every standardized and near-standard ECMAScript feature - Modular design with hundreds of individually importable polyfill paths - Pure version available for libraries that cannot pollute globals - Tight integration with Babel for automatic, usage-based polyfilling - Regularly updated as new TC39 proposals reach maturity ## Comparison with Similar Tools - **Babel** — Transpiles syntax but relies on core-js for runtime feature polyfills - **Modernizr** — Detects feature support but does not polyfill missing features - **es-shims** — Individual polyfill packages per proposal; less integrated than core-js - **polyfill.io** — CDN-based polyfill service that detects the browser and serves only needed code; relies on core-js internally ## FAQ **Q: Do I still need core-js if I target only modern browsers?** A: If your target browsers natively support all features you use, you can skip it. Babel preset-env with a browserslist config will include only the polyfills your targets actually need. **Q: What is the difference between core-js and core-js-pure?** A: core-js patches global constructors and prototypes (Array.prototype.flat, Promise, etc.). core-js-pure exports standalone functions without modifying globals, which is safer for libraries. **Q: How does core-js affect bundle size?** A: A full import adds roughly 50-80 KB minified. Using Babel's useBuiltIns: "usage" or importing specific paths can reduce this to a few KB. **Q: Is core-js actively maintained?** A: Yes. The project continues to track TC39 proposals and ECMAScript editions, though the maintainer has noted the sustainability challenges of a project this widely depended upon. ## Sources - https://github.com/zloirock/core-js - https://core-js.github.io/core-js/ --- Source: https://tokrepo.com/en/workflows/asset-115f2756 Author: Script Depot