In Rails 5.2, Active Storage gives us the ability to generate permanent urls that are redirecting to an asset, via unique signed urls at each call.
html:
<img src='/rails/active_storage/blobs/ey...' />
server:
Started GET "/rails/active_storage/blobs/eyJfcmFpbH...
302 Redirected to https://bucket.amazon/image.jpg?X-Amz-Algorithm=AWS4-HMA...
I am wondering about the number of HTTP requests Active Storage is adding to the monolith, one blob_url in the web page = one additional request to the monolith, in order to get the final asset url via 302 redirect. So One page with 20 images => 20 additional requests. (but they are pretty fast)
So my question is : why using this system instead of using the final URL directly (.service_url) :
<img src='https://bucket.amazon/image.jpg?X-Amz-Algo...'> ?
I am thinking of these arguments : (but is there any other?)
- blob_url can be cached server-side because it is permanent (example : fragment caching)
- blob_url can be protected by authentication, it means the unique url could be shared but someone would need authentication in order to see the asset for example (by modifying the rails blob controller)
- Maybe a third one? Better Caching browser-side? Is the browser able to cache the image data with the permanent url? even if the amazon url have a 5-minute expiration?