Our PHP/MVC webapp lets users upload pictures. They get a link for each image, like: http://example.com/images/55 where 55 is the id we store in our database so we can associate users with their pictures. We are not storing the image data inside our database, but actually on Amazon S3.
When the user requests this URL later on, our server produces the actual URL, and issues a header('Location: https://s3.amazonaws.com/example/media/1234') redirect to the browser where 1234 is id 55 obfuscated. We set up this scheme so we can have a ‘permalink’ solution in case the backend changes – the original URL just gets re-mapped behind the scenes.
With this scheme, is it possible to have the client browser cache the entire process? For example, requesting http://example.com/images/55 will avoid hitting our server entirely and request https://s3.amazonaws.com/example/media/1234 directly, or even better, retrieve this image directly from cache. If not, what is the ‘best’ way to structure our link/redirect scheme? We are going to be producing pages with lots of thumbnails and I’d like those to be cached so the UX is smooth.
To my experience, your request is exactly what happens. The browser, in my case Safari 5 on Mac, hits the script URL, get redirected to the CDN and caches the image under the original script URL…
I noticed this because I need the opposite. Same sort of situation but in my case the user wants to change their picture. The upload proceeds fine, but the browser keeps showing the old image… (consider this before you proceed on your path)