Home / Companies / Speakeasy / Blog / Post Details
Content Deep Dive

Writing Zod code that minifies

Blog post from Speakeasy

Post Details
Company
Date Published
Author
Georges Haidar
Word Count
968
Language
English
Hacker News Points
-
Summary

Zod, a powerful tool for writing safe TypeScript code, has significantly influenced how developers build TypeScript SDKs, particularly at Speakeasy, where it has been integral to their SDK generator design. When optimizing SDK sizes for better browser performance, the traditional method of writing Zod schemas, which involves importing the entire library as a single variable, proved less effective in achieving substantial minification. A revised approach involves importing standalone functions from Zod and using local variables, allowing for more efficient minification by tools like esbuild, resulting in a 43% reduction in code size from 512 bytes to 290 bytes. This method, although slightly more cumbersome due to the necessity of importing individual functions, provides a beneficial strategy for developers prioritizing bundle size optimization.