Next.js Discord

Discord Forum

I have a loading animation that I only want to show when the page is hard loaded

Unanswered
Gouty oak gall posted this in #help-forum
Open in Discord
Avatar
Gouty oak gallOP
IE: when the user visits it for the first time, or reloads the page. If the user navigates to it via the nav bar or fwd back arrows, i don't want it to show. any ideas? i tried doing a header search for next-link, but that wasn't working

2 Replies

Avatar
Black-throated Blue Warbler
I mean, what you are describing is cacheing.

You visit a page for the first time (no cache) so it takes a moment to load, loader displays.

You visit same page later on (its cached), loads much faster, no loader displays.
Next.js makes that pretty easy, for example..

When you hover over a Link from next/link by default it prefetches the page before you even click it, resulting in a fast load where the loader wouldn't appear.

If you visit that page directly by entering the url, there was no prefetch so loader would appear.