Unverified Commit e5b834d2 authored by Steven's avatar Steven Committed by Hendrik Liebau

fetch(next/image): reduce maximumResponseBody from 300MB to 50MB (#88588)

Based on our metrics, the P99.9 for a source image is 47 MB so we can
adjust the default setting to be much lower (by changing from from 300
MB to 50 MB) in favor of reducing memory.
parent 39a2f6a8
...@@ -776,22 +776,22 @@ module.exports = { ...@@ -776,22 +776,22 @@ module.exports = {
#### `maximumResponseBody` #### `maximumResponseBody`
The default image optimization loader will fetch source images up to 300 MB in size. The default image optimization loader will fetch source images up to 50 MB in size.
```js filename="next.config.js" ```js filename="next.config.js"
module.exports = { module.exports = {
images: { images: {
maximumResponseBody: 300_000_000, maximumResponseBody: 50_000_000,
}, },
} }
``` ```
If you know all your source images are small, you can protect memory constrained servers by reducing this to a smaller value such as 50 MB. If you know all your source images are small, you can protect memory constrained servers by reducing this to a smaller value such as 5 MB.
```js filename="next.config.js" ```js filename="next.config.js"
module.exports = { module.exports = {
images: { images: {
maximumResponseBody: 50_000_000, maximumResponseBody: 5_000_000,
}, },
} }
``` ```
......
...@@ -140,7 +140,7 @@ export const imageConfigDefault: ImageConfigComplete = { ...@@ -140,7 +140,7 @@ export const imageConfigDefault: ImageConfigComplete = {
disableStaticImages: false, disableStaticImages: false,
minimumCacheTTL: 60, minimumCacheTTL: 60,
formats: ['image/webp'], formats: ['image/webp'],
maximumResponseBody: 300_000_000, // 300MB maximumResponseBody: 50_000_000, // 50 MB
dangerouslyAllowSVG: false, dangerouslyAllowSVG: false,
contentSecurityPolicy: `script-src 'none'; frame-src 'none'; sandbox;`, contentSecurityPolicy: `script-src 'none'; frame-src 'none'; sandbox;`,
contentDispositionType: 'attachment', contentDispositionType: 'attachment',
......
...@@ -96,7 +96,7 @@ function runTests(mode: 'dev' | 'server') { ...@@ -96,7 +96,7 @@ function runTests(mode: 'dev' | 'server') {
search: '', search: '',
}, },
], ],
maximumResponseBody: 300000000, maximumResponseBody: 50000000,
minimumCacheTTL: 60, minimumCacheTTL: 60,
path: '/_next/image', path: '/_next/image',
qualities: undefined, qualities: undefined,
......
...@@ -107,7 +107,7 @@ function runTests(mode: 'dev' | 'server') { ...@@ -107,7 +107,7 @@ function runTests(mode: 'dev' | 'server') {
loaderFile: '', loaderFile: '',
remotePatterns: [], remotePatterns: [],
localPatterns: undefined, localPatterns: undefined,
maximumResponseBody: 300000000, maximumResponseBody: 50000000,
minimumCacheTTL: 60, minimumCacheTTL: 60,
path: '/_next/image', path: '/_next/image',
qualities: [42, 69, 88], qualities: [42, 69, 88],
......
...@@ -1634,7 +1634,7 @@ function runTests(mode: 'dev' | 'server') { ...@@ -1634,7 +1634,7 @@ function runTests(mode: 'dev' | 'server') {
loaderFile: '', loaderFile: '',
remotePatterns: [], remotePatterns: [],
localPatterns: undefined, localPatterns: undefined,
maximumResponseBody: 300000000, maximumResponseBody: 50000000,
minimumCacheTTL: 60, minimumCacheTTL: 60,
path: '/_next/image', path: '/_next/image',
qualities: undefined, qualities: undefined,
......
...@@ -94,7 +94,7 @@ function runTests(mode: 'server' | 'dev') { ...@@ -94,7 +94,7 @@ function runTests(mode: 'server' | 'dev') {
search: '', search: '',
}, },
], ],
maximumResponseBody: 300000000, maximumResponseBody: 50000000,
minimumCacheTTL: 60, minimumCacheTTL: 60,
path: '/_next/image', path: '/_next/image',
sizes: [ sizes: [
......
...@@ -110,7 +110,7 @@ function runTests(url: string, mode: 'dev' | 'server') { ...@@ -110,7 +110,7 @@ function runTests(url: string, mode: 'dev' | 'server') {
loaderFile: '', loaderFile: '',
remotePatterns: [], remotePatterns: [],
localPatterns: undefined, localPatterns: undefined,
maximumResponseBody: 300000000, maximumResponseBody: 50000000,
minimumCacheTTL: 60, minimumCacheTTL: 60,
path: '/_next/image', path: '/_next/image',
qualities: undefined, qualities: undefined,
......
...@@ -18,7 +18,7 @@ describe('fetchExternalImage', () => { ...@@ -18,7 +18,7 @@ describe('fetchExternalImage', () => {
const error = await fetchExternalImage( const error = await fetchExternalImage(
'http://example.com/no-body.jpg', 'http://example.com/no-body.jpg',
300_000_000 50_000_000
).catch((e) => e) ).catch((e) => e)
expect(error).toBeInstanceOf(ImageError) expect(error).toBeInstanceOf(ImageError)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment