# How We Made clarity.js 4.5% Smaller Without Sacrificing Compatibility

DevFeed: [How We Made clarity.js 4.5% Smaller Without Sacrificing Compatibility](<https://devfeed.tech/articles/how-we-made-clarity-js-4-5-smaller-without-sacrificing-compatibility-109132.md>)

Original publisher: [Read original article](<https://clarity.microsoft.com/blog/how-we-made-clarity-js-smaller/>)

Author: Manu Nair

Published: 2026-10-29T11:24:00Z

Content type: article

Language: en

Sources: [Microsoft Clarity](<https://devfeed.tech/sources/microsoft-clarity-blog.md>)

Topics: [Page Speed Optimization](<https://devfeed.tech/topics/page-speed-optimization.md>), [Tool](<https://devfeed.tech/topics/tool.md>), [Integration testing](<https://devfeed.tech/topics/integration-testing.md>)

Tags: [ai](<https://devfeed.tech/tags/ai.md>), [automated](<https://devfeed.tech/tags/automated.md>), [compatibility](<https://devfeed.tech/tags/compatibility.md>), [experiment](<https://devfeed.tech/tags/experiment.md>), [functionality](<https://devfeed.tech/tags/functionality.md>), [js](<https://devfeed.tech/tags/js.md>), [size](<https://devfeed.tech/tags/size.md>), [uncategorized](<https://devfeed.tech/tags/uncategorized.md>)

## AI overview

An automated loop made more than 50 build-and-measure experiments, each followed by test-suite checks, and reduced clarity.js by 1,257 gzip bytes (4.5%) without reducing functionality. The post finds that source-code brevity does not predict compressed size: extracting repeated small helpers and using ||= increased gzip output. Savings came from replacing namespace imports passed as values with named imports (444 bytes), removing whole functions (84), selected Terser options (301), replacing template literals with concatenation (110), and deduplicating a large block (109). Raising the TypeScript target to ES2017, with ES2020 features, could save 2,308 bytes, but was incompatible with Angular sites using Zone.js, which relies on ES5 generator-based async output for Promise interception and change detection. The practical method is to measure gzip output and test changes individually; results depend on the build and compatibility requirements.

## Source excerpt

See how we reduced the clarity.js bundle size by 4.5% using an automated AI experiment loop, while preserving functionality and compatibility. The post How We Made clarity.js 4.5% Smaller Without Sacrificing Compatibility appeared first on Understand your customers | Microsoft Clarity Blog.