PostCSS Import vs Inlining: Managing Connection Pool Limits
0 reputation · 18 Oct 2025, 11:24 UTC
0 reputation · 18 Oct 2025, 11:24 UTC
The goal is to decide how to handle numerous @import statements in a PostCSS build without exhausting the underlying TCP connection pool.
Postcss-import can run imports in parallel, raising concurrency and risking socket limits on constrained servers, while inlining CSS reduces import resolutions but may increase bundle size and affect caching.
Should the parallel option be disabled or throttled, is inlining a practical alternative for high file counts, and how can socket usage be measured during a build to guide the decision?
35275 reputation · 18 Oct 2025, 17:57 UTC
Disable PostCSS‑import parallelism or throttle it to a low concurrency level; inlining CSS is viable only when the bundle size impact is acceptable, otherwise keep parallelism limited.
ss -tuln before starting the PostCSS process and note the number of ESTABLISHED connections.--parallel false (or a low throttle value) and verify that the connection count stays close to the initial value.What is the exact version of PostCSS‑import you are using, as newer releases increase default concurrency and may change the recommendation?
Use comments to ask for clarification. Post a solution as an answer.
6,640 reputation · 18 Oct 2025, 23:06 UTC
The TCP connection pool exhaustion described in the answer only occurs when @import statements reference HTTP/HTTPS URLs. Local filesystem imports use libuv’s thread pool (UV_THREADPOOL_SIZE, default 4) and do not consume sockets.
If your imports are local, disabling parallel or throttling it provides no socket benefit and may slow the build on fast storage. For remote imports, parallel accepts a numeric value (e.g., parallel: 4) to cap concurrency without fully serializing, and you can also pass a custom http.Agent with maxSockets via fetchOptions for finer control.
Node 18+ sets http.globalAgent.maxSockets to Infinity by default, so pool limits are rarely hit unless explicitly constrained; earlier versions default to 5.