Replies: 48 comments 74 replies
-
I actually expected this functionality when I tried out next/image. Then when it didn't work I couldn't find anything about it in the docs. Would be really great if next/image worked with export |
Beta Was this translation helpful? Give feedback.
-
Why was this issue moved to discussion? What's the difference between "Feature request" label under issues and the "Ideas" label under discussion? |
Beta Was this translation helpful? Give feedback.
-
Any plans of supporting this feature in near future?
cc: @leerob @timneutkens |
Beta Was this translation helpful? Give feedback.
-
Next is claiming that it supports static side generation. It is also proud of providing image optimization. Now I had to learn the hard way after converting my code from Gatsby to Next, that we cannot have both even though it is part of the core library. That is a real bummer. @timneutkens I have found this idea here only after I started writing a feature request and started looking for a similar request at this place (didn't find one on the issues). So please don't take the 👍 too serious. Also, maintainers are closing related issues because this functionality is intended, which makes them and this discussion thread harder to find and reduces the interactions with these. There are several issues pointing to this missing feature: ... just to name a few I was able to find without investing too much time. Generating these images during export should be provided by Next. Resizing images using NodeJS is already implemented (used by next start) and we only need to generate resolution sensitive image tags in the static HTML plus the image files. Since this is OSS: Can I help somehow? |
Beta Was this translation helpful? Give feedback.
-
Yup, it's a problem, especially when it's not being handled at all. Not only it does not optimize images, but actually brakes the generated static site. I'm really surprised there's still no huge red warning in the docs (1, 2) that using Did anybody try using Netlify with |
Beta Was this translation helpful? Give feedback.
-
We've got a naive but workable workaround in https://github.com/minvws/nl-covid19-data-dashboard/pull/1434/files#diff-f9318ad2bcfcfdc021518b7d9f7c102c4b32461be1c838a624595d100c6ef5c5 This would be easier if this was built-in, for sure. |
Beta Was this translation helpful? Give feedback.
-
Same here... for us the whole point of choosing Next.js was the ability to |
Beta Was this translation helpful? Give feedback.
-
The issues is still open and no possible fixes yet. I only used Next.js for it's image optimization, but had to learn myself that it won't work on export |
Beta Was this translation helpful? Give feedback.
-
On the one hand, next.js docs say:
And then, on the other,
It seems to me it only works this way because Vercel offers a premium image optimisation service. If next.js optimised images at build time, then they fear losing customers. This is mind boggling. I've been thinking for a few days whether to go with next.js or gatsby for a new project. This settles it. |
Beta Was this translation helpful? Give feedback.
-
Based on the number of upvotes and thumbs up on this idea, this is the 2nd most requested feature on Next.js right now. Come on, please give us some sort of announcement that this feature is coming and when we can expect it. I was ready to switch from Gatsby to Next.js, and was completely baffled that the seemingly simple requirement to have I don't want to completely change my hosting provider and webserver configuration just for an on-demand image optimization feature that I don't need, and I don't like the security implications of having a Node.js app run permanently on a public server. What if a security flaw is discovered in some Node.js networking functionality? To me, one of the huge benefits of having an entirely static site is not having to worry about security updates anymore. Requiring a permanently running Node.js app for an essential web feature like images completely defeats this benefit. |
Beta Was this translation helpful? Give feedback.
-
I recently bumped into this issue as well and was surprised to find out that Despite there being a workaround, it would be great to have the ability to optimize images during build out of the box and without having to jump through additional hoops. Also, highlighting the limitations of |
Beta Was this translation helpful? Give feedback.
-
Edit: I've updated the main discussion with the latest updates 🚀 |
Beta Was this translation helpful? Give feedback.
-
I've only recently switched to using Next/Image, but I bumped into this rather quickly. It's not just next export, it would be nice to be able to generate optimized images during build time in general, so that users don't have to wait 2-3 seconds for important images to load the first time they visit the site. Similar to how we can statically generate pages during build time, optimizing images seems like a reasonable next step. Some people rely quite heavily on static generation, with frequent rebuilds, and the images need to be recreated after every build, so they experience this initial delay quite regularly. The easy way to deal with this is to just open the important pages once after each rebuild and scroll through them, and screw around with your browser width so that all the important images get generated at different sizes, but there has to be a more elegant way. |
Beta Was this translation helpful? Give feedback.
-
We've just released sidepix, a picture (as in At Neugelb we've been using a version of sidepix in production, but the open source version is rather different, arguably improved but also less tested. We'll be adding documentation and minor features in the next weeks. Of course, any feedback is welcome! |
Beta Was this translation helpful? Give feedback.
-
Ended up by writing JS script (gulp task) which searches for project images (using globby), then resizes them using imagemagick and builds JSON with module.exports = {
"Products": {
"decode": {
"images": {
"main01Open": {
"srcSet": "/generated/pages/products/decode/images/main-01-open-e9e51a84-300.png 300w,/generated/pages/products/decode/images/main-01-open-e9e51a84-320.png 320w,/generated/pages/products/decode/images/main-01-open-e9e51a84-640.png 640w,/generated/pages/products/decode/images/main-01-open-e9e51a84-960.png 960w,/generated/pages/products/decode/images/main-01-open-e9e51a84-1200.png 1200w",
"src": "/generated/pages/products/decode/images/main-01-open-e9e51a84-640.png"
},
....
}
}
}
} Usage: <img
src={Assets.Products.decode.images.main01Open.src}
srcSet={Assets.Products.decode.images.main01Open.srcSet}
alt="Opening Xib or Storyboard."
/> |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
I've updated the main message with more details - also:
Please keep the conversation on topic, upvoting current solutions or options for build-time image optimization. Thank you! |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
Looking at the props for As such
Afterwards, both the original (and optimized) images would be cached and also exported in the I'm planning to port a client website to Next.js from Gatsby, and the lack of static image optimization is holding me off (SSR/DSG is out of question for this project). I prefer not to use external libraries for image optimization. I'm not familiar with Next.js internals, but I imagine this isn't very hard to achieve. Has anyone work with this? I'd like to contribute if no one is working on this (yet). |
Beta Was this translation helpful? Give feedback.
-
I think long build time would NOT be a problem with static image optimization for all occurrences of
|
Beta Was this translation helpful? Give feedback.
-
Dear team! As indicated above, this is - so far - the top-voted discussion item and, from a practical point of view, our current obstacle as well. It is always tough to tell our customers why their images are loaded so slowly from our CMS, although they are known and accessible at build time. Runtime optimization is important, but seeing something right away is even more important. A flag to generate cached (and optimized) images would indeed come in handy on the final build. There is no need to include this routine in every single build. For what it's worth, this logic could alternatively be applied when starting the app on the deployed server. During build a list of image urls can be generated which could then be pre-fetched on boot. Any thoughts/updates on this? |
Beta Was this translation helpful? Give feedback.
-
Big appreciation to Next.js team for doing great work! Still there is a lot of possibilities to enhance further. Static image export is one of them. Purpose: fully static, provider agnostic, secure and solid SSG website. First trying recommendations from here #36431 (comment) Then this: https://www.npmjs.com/package/next-image-export-optimizer Then trying each option from here: https://stackoverflow.com/questions/70500084/how-to-export-static-images-on-nextjs Then thoroughly reading this: https://nextjs.org/docs/app/api-reference/components/image After all this steps I still don't have a clue how to properly (automatically) make static images that can output this html:
At least it's possible to manually write this for each image. |
Beta Was this translation helpful? Give feedback.
-
While Next.js does not officially support image optimisation at build time, a workaround is possible by using the following library. The library supports basic use cases, as well as functionality similar to Next.js |
Beta Was this translation helpful? Give feedback.
-
In my use-case, I upload the static assets to S3 during build-time and use CloudFront for caching. I spent days on it only to figure out that Image only generates on-demand, so I have to jump back to point CloudFront to the domain instead of the S3 bucket. As others said, Static generation would not be completed without this feature. |
Beta Was this translation helpful? Give feedback.
-
Edit: This post has been updated by @leerob to include the current solutions and related issues.
Overview
next/image
does not currently perform image optimization duringnext build
, and instead optimizes images on-demand. This was done to prevent long build times when optimizing many images. Build time optimization is one of the top requests from the community and is something we're exploring solutions for. In the meantime, here are the current solutions.Current Solutions
Static Exports
Image Optimization through
next/image
can still be used with a static export by defining a custom image loader innext.config.js
. For example, you can optimize images with a service like Cloudinary:This custom loader will define how to fetch images from a remote source. For example, the following loader will construct the URL for Cloudinary:
You can then use
next/image
in your application, defining relative paths to the image in Cloudinary:Disabling Optimization
If you want to use
next/image
(for maintaining aspect ratio, etc) but don't want any image optimization, you can opt-out as of 12.3:Checking optimized images into git
You optimize your images are part of a separate pipeline and check those files into git for consumption in your
public
folder. This is a good solution if you are worried about build times, as they compute and run on your local machine pre-commit. This ensures there's no build time overhead.Related Issues
#18356
Beta Was this translation helpful? Give feedback.
All reactions