-
SummaryCurrently facing high SS Page generation on my NextJS Application site, with GSSP props payload < 128Kb. But still im suffering long server response. Any insights from the wide audience is appreciated. 🫡 Attached below a simplified version on how my GSSP looks like End result logs on "finish"
TTFB > 2seconds on production. Additional informationexport const getServerSideProps = async (context: Context) => {
const { query, resolvedUrl, req, isServer, res } = context;
let endTime;
const startTime = process.hrtime()
let tsrt: number;
let fsrt: number;
// Function to measure TTFB
const measureTTFB = (res: any) => {
try {
const originalWriteHead = res.writeHead;
res.writeHead = function (...args: any[]) {
try {
const writeHeadTime = performance.now();
if (isServer && Array.isArray(startTime)) {
const startTimeMs = startTime[0] * 1000 + startTime[1] / 1000000;
fsrt = writeHeadTime - startTimeMs;
} else {
fsrt = writeHeadTime - (startTime as number);
}
return (originalWriteHead as ServerResponse["writeHead"]).apply(this, args);
} catch (error) {
console.error("Error in writeHead timing:", error);
return (originalWriteHead as ServerResponse["writeHead"]).apply(this, args);
}
};
} catch (error) {
console.error("Error setting up TTFB measurement:", error);
}
};
measureTTFB(res);
res.on("finish", () => {
console.log(
`tsrt: ${tsrt?.toFixed(2) || "N/A"} ms, fsrt: ${fsrt?.toFixed(2) || "N/A"} ms`
);
});
---
Multiple API calls
----
endTime = process.hrtime(startTime);
tsrt = endTime[0] * 1000 + endTime[1] / 1000000;
return {
props: {
...
} ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Are you doing your API calls sequentially? Could you post some pseudocode of what's going on there? |
Beta Was this translation helpful? Give feedback.
-
It looks like your getServerSideProps isn't inherently heavy in terms of payload, but the TTFB > 2s suggests the issue likely stems from either blocking I/O or inefficient API orchestration. Here are a few focused suggestions to help diagnose and improve:
|
Beta Was this translation helpful? Give feedback.
-
@icyJoseph @AzizB283 Thanks for providing the valuable inputs even though i had tried some of them before as I could.
File like below is generated based on the config. But they have no improvement for our case.
|
Beta Was this translation helpful? Give feedback.
@icyJoseph @AzizB283 Thanks for providing the valuable inputs even though i had tried some of them before as I could.
Fortunately thank god finally we found the root cause. It's due to an experimental.optimizeCss setting in the NextConfig.
Somehow blocking the page from SSR / html generation. I took up to x seconds to load
File like below is generated based on the config. But they have no improvement for our case.
Inlined 2.73 kB (1% of original 181.42 kB) of https://cdn/static-assets/web-listing/_next/static/css/cea7638987e8d9e3.css.
Inlined 97 bytes (1% of original 5.65 kB) of https://cdn/static-assets/web-listing/_next/static/css/c99e85fb1…