Next.js Discord

Discord Forum

Image load slow next14

Unanswered
Grass Carrying Wasp posted this in #help-forum
Open in Discord
Grass Carrying WaspOP
Hi guys, looking for some advice to speed up image load time. some of these images are taking up to 8-10 seconds, most of these are less than 1 MB, the biggest one is the gif at 1.6MB. I have a <Loader/> component that loads while the images load; how could I optimise the code further?
(FYI I removed the tailwind classes)



'use client';
import Image from "next/image";
import { useState, useEffect } from "react";
import Loading from "./Loading";

export default function Home() {
  const [showLoading, setShowLoading] = useState(true);
  const [imagesLoaded, setImagesLoaded] = useState(0);

  const imagesToLoad = 3;

  const handleImageLoad = () => {
    setImagesLoaded((prev) => prev + 1);
  };

  useEffect(() => {
    if (imagesLoaded === imagesToLoad) {
      setShowLoading(false);
    }
  }, [imagesLoaded]);

  return (
    <>
      {showLoading && <Loading />}
      <div>
        <div>
          <a href="https://xyberdreams.com/">
            <div>
              <Image
                src="/animation.gif"
                width={700}
                height={700}
                alt="glasses"
                onLoadingComplete={handleImageLoad}
              />
            </div>
          </a>
        </div>

        <div>
          <div>
            <Image
              src="/image.webp"
              width={400}
              height={400}
              alt="text"
              onLoadingComplete={handleImageLoad}
              className="w-full h-full max-w-[1200px] max-h-[1200px]"
            />
          </div>
        </div>
      </div>
    </>
  );
}

23 Replies

Grass Carrying WaspOP
any help would be much appreciated 🙏
Grass Carrying WaspOP
@Clown 🙏 🙏
Netherland Dwarf
You can compress the image sizes
And use blurDataUrl
@Netherland Dwarf You can compress the image sizes
Grass Carrying WaspOP
ahh I already compressed the images
Netherland Dwarf
And use .webp format
Oh ok
@Netherland Dwarf And use .webp format
Grass Carrying WaspOP
currently using webp for everything except for the gif
I dont think there's any other way out of it tbh. The most you can do is try resize them better or make them smaller somehow
Netherland Dwarf
Hmm i just double checked and currently next doesnt offer much support for optimization for .gifs
The other solution is make ot a video
Instead of .gif
Next supports video optimization
@Clown I dont think there's any other way out of it tbh. The most you can do is try resize them better or make them smaller somehow
Grass Carrying WaspOP
if I set the width and height less e.g., from 400x 400x to 200x 200x how does that change the output?
Grass Carrying WaspOP
makes it smaller?
Take a lot at priority and quality too
@Netherland Dwarf Next supports video optimization
Grass Carrying WaspOP
ahh and autoplay the video?
Netherland Dwarf
Yes
You can use next cloudinary
Grass Carrying WaspOP
would that be smaller than gif likely?
Netherland Dwarf
Which does buffer
@Netherland Dwarf You can use next cloudinary
Grass Carrying WaspOP
will take a look at that in a bit thanks