-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image Redirect Caching with Seed #121
Comments
Hi @benkaiser! Thank you for reaching out. The reason why all redirects from picsum.photos are 302s and have non-cache directives, is that the resulting image URL we redirect to is not guaranteed to be static, even though they generally are, and we do serve the same image for all When an image request comes in to picsum.photos, our API service validates the request, and builds the redirect to our image processing service (fastly.picsum.photos). Images are then processed/served by our image processing service as needed, backed by a CDN, but these URLs may change over time. This gives us the freedom to re-architect the backend without service interruption. This does mean that a client always pays the cost of having to make the request that results in the actual redirect, but the images served by the image service on fastly.picsum.photos (post redirect) does set cache headers, so the actual image should be getting cached appropriately (given the mostly static URL). If this is not the case, please let me know, and I'm happy to look over the cache headers et-al. |
Thanks for the detailed info @DMarby ! So if that's the case, I should avoid storing the picum.photos url and instead store the redirected url and then always render the image tag with that if I want to give the user the smoothest most-cachable experience? Is there a middle ground option where we could have some kind of TTL on the redirect of a week or something, rather than using no-cache (specifically for seed URLs)? |
In general, you should only be storing the There is likely a viable middle-ground with shorter-lived TTLs for seed URLs, yeah! |
Sounds good. In the meantime I'll look into caching the redirects/image caching with service worker to try to improve client performance. |
Is there a particular reason redirects are instructed to not cache + use a 302 redirect (instead of 301), even when calling with a specific seed url?
I am calling endpoints such as:
https://picsum.photos/seed/7890/400/200
Which will always give me the exact same image. So why instruct the browser to not cache? Seems like it increases the load on the service, and provides a poorer experience for users having to load the image every time it is rendered on the page (despite not changing).
This is a very low priority request, just curious to the background. Absolutely love the work here and this service is absolutely invaluable!
The text was updated successfully, but these errors were encountered: