9

I am using NEXT/Image component and facing this issue:

When I open the source code on chrome the image src is this:

https://www.example.com/_next/image?url=%2Fimages%2Fhome%2FDog-image-1.jpg&w=384&q=100

but when I make google crawl the website in search console and see the code how google sees it, I see the image URLs like this:

https://www.example.com/_next/image?url=%2Fimages%2Fhome%2FDog-image-1.jpg& amp;w=384& amp;q=100

The URL has changed the "&" character to "& amp;" which is stopping google from indexing the images because this URL gives an error of:

400: BAD_REQUEST Code: INVALID_IMAGE_OPTIMIZE_REQUEST

and google is not able to crawl these images and index them because it seems like a broken link to it.

Any idea why this is happening?

Thank You.

1

2 Answers 2

17

I came a cross this issue today as well. I found an answer to this question solves my problem. Create a loader function and pass it to the image component.

const loaderProp =({ src }) => {
    return src;
}

<Image
      src={currentImage.imageurl}
      alt={currentImage.imageurl} 
      layout="fill"
      className={styles.imageSize} 
      loader={loaderProp}
/>
Sign up to request clarification or add additional context in comments.

2 Comments

thank you very much @Thammarith, you have saved my life. I've been spending several hours stucking in this issue.
Side note: setting the alt text of an image to the url really isn't a good idea, people using screen readers and other accessibility tools will struggle making any sense of your content.
0

It looks like Next solve it in version 14 by using overrideSrc :

In some cases, it is not desirable to have the src attribute generated and you may wish to override it using the overrideSrc prop.

For example, when upgrading an existing website from to , you may wish to maintain the same src attribute for SEO purposes such as image ranking or avoiding recrawl.

 input.jsx:
<Image src="/me.jpg" overrideSrc="/override.jpg" />

Would generate:

output.html:
   <img
  srcset="
    /_next/image?url=%2Fme.jpg&w=640&q=75 1x,
    /_next/image?url=%2Fme.jpg&w=828&q=75 2x
  "
  src="/override.jpg"
/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.