Use suspense, nextjs supports it but there are things worth considering before using it.
Assuming you're using NextJs 13 with app directory:
Create a file loading.js or anyname in app directory. This will be your layout to show while the DOM is rendering, design it however you want, put gif/svgs whatever is required.
loading.js
export default function Loading() {
return (
<div className="fixed inset-0 bg-blue-500 z-[10000] flex flex-1 items-center justify-center">
Loading
</div>
);
}
then your layout file should look like this:
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
<Suspense fallback={<Loading />}>{children}</Suspense>
</body>
</html>
);
}
As long as your DOM is rendered its gone, you'll see its rendered like a flas on some and slow on others that depends on your page size. You can look up, delaying Suspense or adding lazy component if you need.
Tip: use Lottie Animations for making a loading or any smaller sized svg and rotate is using css animations to keep suspense content smaller.