Replies: 1 comment
-
Since Next.js still lacks native support for downloading remote images and including them in static builds, workarounds remain necessary. Existing solutions, such as next-image-export-optimizer, often require defining image URLs in advance. This approach doesn't make sense when building a site dynamically based on content from an external CMS, such as Cosmic.js. To address this, I’ve gathered and refined a solution in the following GitHub repository: 🔗 https://github.com/PioterAndrzejewski/next-export-with-static-images In short, the approach works as follows: Custom Image Loader: Generates optimized image URLs using imgix. HTML Parsing Script: Analyzes generated HTML files and downloads all referenced remote images. Path Replacement: Updates src and srcset attributes in HTML files to point to the downloaded local image assets. This method ensures that all external images are properly downloaded, linked, and included in the final static build output. If you're also struggling with this limitation in Next.js, feel free to check out the repository and share your thoughts! |
Beta Was this translation helpful? Give feedback.
-
Summary
I want to host Next.js somewhere as static files. (e.g. Azure Static Web App).
I use this configuration:
It was done following documentation https://nextjs.org/docs/messages/export-image-api
And I can get a static site. However, images are unoptimized.
Is it possible to get optimized images during the build(with output=export) as static content?
Any recipes? (including 3rd party solutions)
Additional information
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions