Reputation:
When I'm using getServerSideProps with next js and it almost takes 5 or 6 seconds for the page to load . I tried using only one url to fetch and not many but again it takes alot for the page to load .
export const getServerSideProps = async (ctx) => {
let data ;
try {
data = axios.get("url")
} catch(e){
data = "error"
}
return {
data: data,
};
};
I was wondering is there any trick to speed up getServerSideProps data fetching so I could have faster initial page load ?
Upvotes: 11
Views: 10124
Reputation: 324
got this solution while searching for this bug
const isServerReq = req => !req.url.startsWith('/_next');
function Post({ post }) {
// Render post...
}
export async function getServerSideProps({ req }) {
const initData = isServerReq(req) ? await fetch(...) : null;
return {
props: {
initData,
},
}
}
issue: https://github.com/vercel/next.js/issues/13910
Upvotes: 1