Next.js Discord

Discord Forum

Fetch req not cached

Unanswered
Red-breasted Flycatcher posted this in #help-forum
Open in Discord
Red-breasted FlycatcherOP
import Image from "next/image";

async function getRandomDog() {
const res = await fetch("https://dog.ceo/api/breeds/image/random");
const data = await res.json();
return data;
}

export default async function Home() {
const randomDog = await getRandomDog();
console.log(randomDog);

return (
<main className="flex min-h-20 flex-col items-center justify-between p-12">
<h1 className="text-5xl mb-12">Hello Home!</h1>
<Image
src={randomDog.message}
width={500}
height={500}
alt="Random dog"
/>
</main>
);
}

6 Replies

Red-breasted FlycatcherOP
so there is no way to test caching on dev mode ?
European sprat
npm build && npm start
@Red-breasted Flycatcher so there is no way to test caching on dev mode ?
no because who knows, you could have modified some logic related to data fetching, then the data fetching has to be run again else it would be an obvious bug. that's why data caching is disabled in dev mode and it's a feature
you have to use prod mode by using the commands jarrah gives you above
Red-breasted FlycatcherOP
Thank you 👍