Next JS Image Optimization

Viewed 567

How can I use the NextJS Image element in raw HTML response from the server something like:

HTML =
"<div>
<p> Some Random text</p>
<img src="image1.jpg" />
<img src="image2.jpg" />
<p> Some Random text</p>
<img src="image3.jpg" />
<img src="image4.jpg" />
<div>"
1 Answers

The Next.js Image element is React component so it can only be used in React (with Next.js).

export default function Page() {
   return (
      <Image src="/image.png" layout="fill" />
   )
}

If you want image optimization with just raw HTML, I would recommend installing ImgBot in a GitHub repository, and it will optimize the images for you and save them in the file.

Related