How come when I use getStaticPaths in production on my local server the pages load instantly but deployed on Vercel they don't?

Viewed 357

Hi I'm using NextJs and I am having an issue that when my app is hosted on my local server the pages that are pre loaded with getStaticProps are loading in a few ms but when hosted on Vercel it is taking 300ms to load. Does anyone have any suggestions on how I can get my pages to load quicker on Vercel?

My app is currently hosted at https://next-movie-delta.vercel.app/

and my github repo is https://github.com/lewisRotchell/next-movie

My getStaticPaths code looks like:

    export async function getStaticPaths() {
  const movies = await getMovies();

  const bigMovieArray = [
    ...movies[0].results,
    ...movies[1].results,
    ...movies[2].results,
  ];

  const paths = bigMovieArray.map((movie) => ({
    params: { movieId: movie.id.toString() },
  }));

  return {
    paths,
    fallback: "blocking",
  };
}

and the getMovies code looks like :

export async function getMovies() {
  const urls = [newReleasesUrl, popularMoviesUrl, topRatedMoviesUrl];

  try {
    let data = await Promise.all(
      urls.map((url) => fetch(url).then((response) => response.json()))
    ).catch((error) => console.log(error));
    return data;
  } catch (error) {
    console.log(error);
  }
}

Thanks :)

1 Answers

I've managed to fix the problem! I changed the linking from withRouter to a tag from next/link and it has fixed my issue!

Related