0

I have a website with a page containing a lot of images. Those images will never change on the server (if they change, the URI on the page referencing them will have a different version parameter, in an URI such as http://cdn.example.com/image1.jpg?v=123).

The images are served with Cache-Control: max-stale=31536000, public header as advised in an answer on StackOverflow.

ETag header is disabled, as recommended in another answer.

When I press F5 in Chrome, everything works as expected: the page reloads, and there are no requests for images. However, when I press Ctrl+F5, the browser does the requests to the server.

I want it to behave as for the favicon: do a request to the server only when explicitly asked (that is a Ctrl+F5 on the specific image), and avoid a roundtrip to the server when I do Ctrl+F5 on a page containing the images.

Is it possible?

If yes, what headers should I put in the response?

Notes:

  • The developer console remains closed during the tests.
  • The content is directly served from a server; no reverse proxies.
  • When the image is requested after I press Ctrl+F5 on a page, the request contains Cache-Control: no-cache, making it impossible to respond with HTTP 304.
Arseni Mourzenko
  • 50,338
  • 35
  • 112
  • 199
  • 2
    https://www.greenbytes.de/tech/webdav/rfc8246.html might be of interest. – Julian Reschke Nov 12 '17 at 05:40
  • Possibly you could replace the `src` attribute with a custom `data-src` attribute, then use javascript to load the images. Depending on how the javascript was written, you could probably ensure that ctrl+f5 did not cause a redownload of the images. Admittedly, using this technique will break your site for noscript users. – Brian Nov 13 '17 at 14:06

0 Answers0