Serve all S3 images from CDN


Hi guys,

Following this topic, would it be possible to serve all images from the CDN.

Currently, we noticed that:
1/ Smaller images are served from the origin server directly. This includes avatars & thumbnails.
2/ Larger images are correctly served from the DNS

In my case, it slows down the experience for users located far away from our server (particularly in India).


(Sam Saffron) #2

You need to define a second CDN via the discourse CDN global setting, one that origin pulls from the app

(Bhanu Sharma) #3

@sam any guides on meta about how to do it?

(Sam Saffron) #4

Nothing cloud front specific, but this works Discourse CDN set up with KeyCDN on cloud front you can have a single domain serve 2 origins

(Bhanu Sharma) #5

I think I have tried this but the avatars were still being loaded from my own server. I’ll recheck it today.

Thanks for pointing in the right direction.


Out of curiosity, since all images are stored in S3, why can’t we use our S3 CDN to serve all images even small ones?

If we setup another global CDN aren’t we going to store static content twice?

(Sam Saffron) #7

Technically we can eventually get there but it would involve a fairly significant amount of work dealing with avatars, the client has a “template” string for avatars where it just plugs in a number, it also only resizes the avatars it needs to on demand. If we were to serve unconditionally from s3 we would have to unconditionally resize and upload upfront and come up with a parallel upload scheme.

So… to save us multiple weeks of engineering just setting up a second origin on cloudfront does the trick.

[Paid] Restore broken images uploaded to S3