Angular SSR caches HTML to cut server render time from 17ms to 1.9ms
Angular's server-side rendering re-renders pages for every visitor by default, wasting server resources when content hasn't changed. A developer built ng-ssr-caching, an Express middleware that stores rendered HTML and serves it without re-rendering, reducing response time from 17.2ms to 1.9ms on a 28KB page. A key optimization involves pre-computing ETags and content-length at cache-store time rather than on every response, avoiding repeated body hashing. The middleware also handles security by automatically bypassing caching for requests with Authorization headers, and allows developers to specify session cookies that should trigger cache bypasses. The author warns that misconfigured shared caches risk serving one user's personalized page to another, making correct bypass rules critical.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in