Next.js Discord

Discord Forum

Fetching product takes long time? (On vercel)

Unanswered
Waterman posted this in #help-forum
Open in Discord
Hello I am fetching data from a product by matching the url with one of the products I have in my database(mongodb shared hosting), the problem is that it takes so long time for it to load into the specific page where the product is,

the thing is that it doesn't seem to be cached in the same way it is when I am displaying multiple products, to demonstrate this problem on your own you can visit levecco.se, then click on "Mössor" in the header to navigate to where the products actually load fast, because it is cached. But when you click on one of the products it takes 2-3 seconds before entering that page. Atleast for me. I know I can just implement a spinner but isn't there a better way of not making my customers wait so long?

here is the code that demonstrates how I fetch the single product page
export default async function Page({ params }: { params: { namn: string } }) {
  await mongooseConnect();

  if (params.namn) {
    const res = await EnkelProdukt.findOne({ url: params.namn }).exec();
    data = res;
  }

more code...

0 Replies