This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Commit 6baba7a
authored
Add upstream
This solves the main use case from Issue vercel#19914.
Previously, we would set the `Cache-Control` header to a constant and rely on the server cache. This would mean the browser would always request the image and the server could response with 304 Not Modified to omit the response body.
This PR changes the behavior such that the `max-age` will propagate from the upstream server to the Next.js Image Optimization Server and allow browser caching. ("upstream" meaning external server or just an internal route to an image)
This PR does not change the `max-age` for static imports which will remain `public, max-age=315360000, immutable`.
#### Pros:
- Fewer HTTP requests after initial browser visit
- User configurable `max-age` via the upstream image `Cache-Control` header
#### Cons:
- ~~Might be annoying for `next dev` when modifying a source image~~ (solved: use `max-age=0` for dev)
- Might cause browser to cache longer than expected (up to 2x longer than the server cache if requested in the last second before expiration)
## Bug
- [x] Related issues linked using `fixes #number`max-age to optimized image (vercel#26739)1 parent 2592738 commit 6baba7a
File tree
3 files changed
+146
-85
lines changed- packages/next/server
- test/integration/image-optimizer/test
3 files changed
+146
-85
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
158 | 159 | | |
159 | 160 | | |
160 | 161 | | |
161 | | - | |
162 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
163 | 165 | | |
164 | 166 | | |
165 | 167 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
171 | 176 | | |
172 | | - | |
173 | | - | |
| 177 | + | |
| 178 | + | |
174 | 179 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | 180 | | |
180 | 181 | | |
181 | 182 | | |
| |||
271 | 272 | | |
272 | 273 | | |
273 | 274 | | |
274 | | - | |
275 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
276 | 291 | | |
277 | 292 | | |
278 | 293 | | |
| |||
342 | 357 | | |
343 | 358 | | |
344 | 359 | | |
345 | | - | |
346 | | - | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
347 | 376 | | |
348 | 377 | | |
349 | 378 | | |
350 | 379 | | |
351 | | - | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
352 | 389 | | |
353 | 390 | | |
354 | 391 | | |
| |||
362 | 399 | | |
363 | 400 | | |
364 | 401 | | |
| 402 | + | |
365 | 403 | | |
366 | 404 | | |
367 | 405 | | |
368 | 406 | | |
369 | 407 | | |
370 | 408 | | |
371 | | - | |
| 409 | + | |
372 | 410 | | |
373 | 411 | | |
374 | 412 | | |
375 | | - | |
| 413 | + | |
376 | 414 | | |
377 | 415 | | |
| 416 | + | |
| 417 | + | |
378 | 418 | | |
379 | | - | |
380 | | - | |
| 419 | + | |
| 420 | + | |
381 | 421 | | |
382 | | - | |
383 | 422 | | |
384 | 423 | | |
385 | 424 | | |
386 | 425 | | |
387 | | - | |
| 426 | + | |
388 | 427 | | |
389 | 428 | | |
390 | | - | |
| 429 | + | |
| 430 | + | |
391 | 431 | | |
392 | 432 | | |
393 | 433 | | |
394 | 434 | | |
395 | | - | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
396 | 460 | | |
397 | 461 | | |
398 | 462 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
789 | 789 | | |
790 | 790 | | |
791 | 791 | | |
792 | | - | |
| 792 | + | |
| 793 | + | |
793 | 794 | | |
794 | 795 | | |
795 | 796 | | |
| |||
0 commit comments