0

I am working on a Laravel application which is based on a social network. Images are stored on S3 bucket where pricing is based on the number of GET/PUT/DELETE.... requests. I want to reduced the number of request sent to the S3 buckets in any way.

Scenario: Imagine a facebook post and comments

A user's profile picture is being pulled from S3 bucket on a page load. In the comments section of a post a user has commented 10 times. I write a code as usual

<img src="https://s3-ap-southeast-1.amazonaws.com/somebucket/32431435696950423.jpg">

for each comment a new request is sent to the bucket? or by default the image is cached after the first request and pulled from the cache for the rest?

How do I achieve avoiding a multiple GET request for a single image?

Ashik Basheer
  • 1,531
  • 3
  • 16
  • 36

2 Answers2

2

It depends on browser implementation and your image Cache-Control header. Most of modern browsers support caching. They will cache your image if your image is allowed to be cached, and vice-versa. Check When multiple instances of same images are embedded in an HTML, does that load the image once? question.

AWS S3 can be configured to allow your objects being cached (read how to add cache control in AWS S3).

But, if your site has a high traffic, I suggest you to use AWS CloudFront instead of pure S3. It is a CDN (Content Delivery Network). It is faster and can be cheaper than normal S3.

Community
  • 1
  • 1
Edward Samuel
  • 3,846
  • 1
  • 22
  • 39
1

"or by default the image is cached after the first request and pulled from the cache for the rest?" It is the correct answer only if image has the same source and the file name.

So 10 the same images from one URL will be downloaded once.

Grzegorz Gajda
  • 2,424
  • 2
  • 15
  • 23