weserv / images

Source code of wsrv.nl (formerly images.weserv.nl), to be used on your own server(s).
https://wsrv.nl/
BSD 3-Clause "New" or "Revised" License
1.86k stars 187 forks source link

Add `Cache-Control: immutable` header #313

Open GitBoudewijn opened 2 years ago

GitBoudewijn commented 2 years ago

https://images.weserv.nl/faq/#why-am-i-not-seeing-any-http-304-header-when-i-request-a-cached-image

Here in the FAQ it says that you don't use Last-Modified headers in order to prevent 304 requests, however if you take a look at the headers it actually does include Last-Modified:

https://redbot.org/?uri=https%3A%2F%2Fimages.weserv.nl%2F%3Furl%3Dimages.weserv.nl%2Flichtenstein.jpg

Is it supposed to be like that?

Also there's a new way to prevent 304 requests that you aren't using yet, which is adding immutable to the Cache-Control header.

The only downside is that Chrome doesn't support it yet and it's taking them a really long time (see http://bugs.chromium.org/p/chromium/issues/detail?id=611416), but it might be a good idea to add it anyway.

andrieslouw commented 2 years ago

The Last-Modified is inserted by Cloudflare, and I do not see any If-Modified-Since-requests at our servers. So it seems that Cloudflare is intercepting these requests.

The Cache-Control: immutable looks promising, will monitor that one, but implementation in Chromium will be quite important (as proved by https://caniuse.com/mdn-http_headers_cache-control_immutable ).

GitBoudewijn commented 2 years ago

I guess the Vary: Accept-Encoding header is added by Cloudflare as well? Since I don't think you use any encoding.

Chrome will just ignore the immutable directive so you could add it, but it probably won't have much benefit either. Otherwise you can just close this issue and I'll reopen it if the situation changes.

kleisauke commented 2 years ago

Vary: Accept-Encoding is send by Cloudflare as well (but I couldn't find the reason why this is added, curious).

Let's leave this issue open. We can consider adding the Cache-Control: immutable header once it's supported by all modern web browsers.