Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
How to make infinite scroll on Next.js static page?

I'm making portfolio using Next.js and count of projects on page is big enough. I want to start loading images when they get into the current viewport. Such scenario works well with default placeholder prop of next/image.

I'm using custom placeholder (skeleton) component for my images (placeholder is hided when runs onLoadingComplete image prop). If I used SSR then algorithm is clear but with SSG I've reached a dead end.

Will be happy to any advices!

My image component code:

import Placeholder from './placeholder';

const ImageRenderer = ({ url, alt, layout, objFit, width, height }) => {
    const [isImageLoaded, setIsImageLoaded] = useState(false); // loading state

    return (
        <>
            {!isImageLoaded && <Placeholder />}
            <StyledImage
                src={url}
                alt={alt}
                width={width}
                height={height}
                layout={layout}
                objectFit={objFit}
                onLoadingComplete={() => setIsImageLoaded(true)} // runs when next/image is loaded
            />
        </>
    );
};

Placeholder is just div with higher z-index.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can simply add loading="lazy" to your images. It is supported in modern browsers.

Update: For videos you can use preload="none".

about 4 years ago · Juan Pablo Isaza Relatório

0

You should consider using next/image, which by default will only load images as they enter the viewport (you can control that via the lazyBoundary prop). SSG vs SSR does not affect this behavior.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda