Next/Image is loading slow or throw 504 error. #80458
Replies: 2 comments
-
Hi! I understand your frustration with the image optimization performance issues after upgrading to Next.js 14.2.4. This is indeed a known issue that affects many developers, especially when using CloudFront or other CDNs with containers. Root Cause AnalysisBased on your description and the current Next.js codebase, the problem stems from several factors:
Proven Solutions1. Increase Image Optimization Timeout (Recommended)Add this to your module.exports = {
experimental: {
imgOptTimeoutInSeconds: 30, // Increase from default 7 seconds
},
images: {
minimumCacheTTL: 86400, // 24 hours to reduce reprocessing
},
} 2. Reduce Sharp Concurrency for Memory Managementmodule.exports = {
experimental: {
imgOptConcurrency: 1, // Reduce concurrent image processing
imgOptMaxInputPixels: 50000000, // Limit max input pixels to reduce memory usage
},
images: {
minimumCacheTTL: 86400,
},
} 3. Alternative: Disable Optimization for Problematic CasesIf the above doesn't resolve it completely: module.exports = {
images: {
unoptimized: true, // Disables image optimization entirely
},
} 4. Implement External Image Optimization (Production Solution)For production environments with high image loads, consider offloading to external services: module.exports = {
images: {
loader: 'custom',
loaderFile: './my-image-loader.js',
},
} Why This Happens Specifically in 14.2.4+The issue became more pronounced in Next.js 14.2.4 due to:
Verification Steps
References
The Let me know if you need help implementing any of these solutions! |
Beta Was this translation helpful? Give feedback.
-
Thanks for the detailed explanation! Will report back with the results. Appreciate the help! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Since updating to Next.js 14.2.4, we’ve been experiencing significant delays when serving some images from the
public/
directory usingnext/image
.Problem
This issue did not occur in Next.js 13.5.6, which served images normally under the same environment.
Our Environment
Related
This behavior seems very similar to the issue described here on StackOverflow, where others reported long delays or timeouts during image optimization in production.
Request
If anyone has faced similar issues after upgrading to Next.js 14, or has suggestions for how to mitigate this (e.g. base image, config settings, sharp version), I’d really appreciate your input.
Thanks in advance!
Additional information
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions