# Custom emoji don't use CDN for S3 stored assets in a few pages

**URL:** https://meta.discourse.org/t/custom-emoji-dont-use-cdn-for-s3-stored-assets-in-a-few-pages/159787
**Category:** Support
**Created:** [August 4, 2020, 2:34pm UTC](https://meta.discourse.org/t/custom-emoji-dont-use-cdn-for-s3-stored-assets-in-a-few-pages/159787 "2020-08-04T14:34:06Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Boost](https://avatars.discourse-cdn.com/v4/letter/b/8e8cbc/32.png) [@Boost](https://meta.discourse.org/u/Boost)
#### Post date: [August 4, 2020, 2:34pm UTC](https://meta.discourse.org/t/custom-emoji-dont-use-cdn-for-s3-stored-assets-in-a-few-pages/159787/1 "2020-08-04T14:34:06Z")

</div>

I recently configured my discourse installs to use a CDN and store uploads and site assets in S3 compatible service. So far everything else has worked, but our custom emoji images fail to load.  
When looking at the html I noticed that the URL for one of the emoji is [//thrivecommunityforum.s3.eu-central-1.wasabisys.com/original/2X/6/6b7f95a2cfc7810d26c7e170ebf926ba8634261b.png](https://thrivecommunityforum.s3.eu-central-1.wasabisys.com/original/2X/6/6b7f95a2cfc7810d26c7e170ebf926ba8634261b.png)  
(this doesn’t load because I set an override to prevent public access to the bucket after seeing in the file manager a warning that public write was enabled for the files)  
Whereas all the other uploaded images and site assets correctly reference the CDN I configured: [https://thrivecommunity-uploads.b-cdn.net/original/2X/6/62f6697da0e3cd71a7d4f1eed518641f8428150b.jpeg](https://thrivecommunity-uploads.b-cdn.net/original/2X/6/62f6697da0e3cd71a7d4f1eed518641f8428150b.jpeg)

In-built emoji URLs look like this: [https://thrivecommunity-cdn.b-cdn.net/images/emoji/twitter/thinking.png?v=9](https://thrivecommunity-cdn.b-cdn.net/images/emoji/twitter/thinking.png?v=9)  
So my conclusion is that there might be a bug in the custom emoji handling when generating the image links, which skips out on using the CDN that is configured to be in front of the S3 stored files.

I tried to find relevant topics, but I just found this: [Custom Emoji does not use Amazon S3](https://meta.discourse.org/t/custom-emoji-does-not-use-amazon-s3/35690) which seems outdated as discourse is attempting to use S3 to serve custom emoji on my site.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [August 4, 2020, 2:46pm UTC](https://meta.discourse.org/t/custom-emoji-dont-use-cdn-for-s3-stored-assets-in-a-few-pages/159787/2 "2020-08-04T14:46:41Z")

</div>

Custom emoji for testing

:facepalm:

:mdr:

Non custom emoji

🙂

So standard emoji use one CDN while custom use another, but both are covered by CDN if you do a proper configuration following [Using Object Storage for Uploads (S3 Clones)](https://meta.discourse.org/t/using-object-storage-for-uploads-s3-clones/148916) to the letter.

Not a bug, this is expected behavior because standard emoji is stored inside the app codebase and custom is just a normal site upload.

---

<div class="post-metadata">

### Author: ![Boost](https://avatars.discourse-cdn.com/v4/letter/b/8e8cbc/32.png) [@Boost](https://meta.discourse.org/u/Boost)
#### Post date: [August 4, 2020, 3:00pm UTC](https://meta.discourse.org/t/custom-emoji-dont-use-cdn-for-s3-stored-assets-in-a-few-pages/159787/3 "2020-08-04T15:00:38Z")

</div>

I did have a look at that thread, and as far as I can tell my configuration should be right:

```plaintext
  DISCOURSE_CDN_URL: https://thrivecommunity-cdn.b-cdn.net
  DISCOURSE_USE_S3: true
  DISCOURSE_S3_REGION: eu-central-1
  DISCOURSE_S3_ENDPOINT: https://s3.eu-central-1.wasabisys.com
  DISCOURSE_S3_INSTALL_CORS_RULE: false
  DISCOURSE_S3_ACCESS_KEY_ID: aaaa
  DISCOURSE_S3_SECRET_ACCESS_KEY: aaaa
  DISCOURSE_S3_CDN_URL: https://thrivecommunity-uploads.b-cdn.net
  DISCOURSE_S3_BUCKET: thrivecommunityforum
  DISCOURSE_S3_BACKUP_BUCKET: thrivecommunityforum-backup
  DISCOURSE_BACKUP_LOCATION: s3

```

---

<div class="post-metadata">

### Author: ![md-misko](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/md-misko/32/126315_2.png) [@md-misko](https://meta.discourse.org/u/md-misko)
#### Post date: [August 4, 2020, 3:28pm UTC](https://meta.discourse.org/t/custom-emoji-dont-use-cdn-for-s3-stored-assets-in-a-few-pages/159787/4 "2020-08-04T15:28:35Z")

</div>

> [@Boost](#):
>
> I recently configured my discourse installs to use a CDN and store uploads and site assets in S3 compatible service. So far everything else has worked, but our custom emoji images fail to load.

I had a similar problem (posts containing custom emojis weren’t marked for rebake during the migration to S3 if there were no other uploads in the raw post, and therefore the cooked link didn’t point to CDN).

I fixed it by deleting and reuploading just one of the custom emojis, and this automatically triggered a task which rebuilt all posts with custom emojis (but I’m sure there is also a rake task which can be used to rebake posts with custom emojis directly).

---

<div class="post-metadata">

### Author: ![Boost](https://avatars.discourse-cdn.com/v4/letter/b/8e8cbc/32.png) [@Boost](https://meta.discourse.org/u/Boost)
#### Post date: [August 4, 2020, 3:30pm UTC](https://meta.discourse.org/t/custom-emoji-dont-use-cdn-for-s3-stored-assets-in-a-few-pages/159787/5 "2020-08-04T15:30:58Z")

</div>

I see the problem in `admin/customize/emojis` as well as in the post editor preview as well as retort reactions on posts done in the past hour fail.  
So this doesn’t just affect old posts that use emoji, but also new posts and parts of the UI (the retort reaction picker also uses the wrong URL like the admin emoji management area).

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [August 4, 2020, 4:38pm UTC](https://meta.discourse.org/t/custom-emoji-dont-use-cdn-for-s3-stored-assets-in-a-few-pages/159787/6 "2020-08-04T16:38:30Z")

</div>

> [@Boost](#):
>
> post editor preview

That is related to [S3 CDN URL ignored when uploading into posts](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898). Added to the original topic.

> [@Boost](#):
>
> retort reactions on posts

Please report on the plugin topic as it is third party.

> [@Boost](#):
>
> problem in `admin/customize/emojis`

This is legit, but low are of effect as it is an admin only page.

---

<div class="post-metadata">

### Author: ![Boost](https://avatars.discourse-cdn.com/v4/letter/b/8e8cbc/32.png) [@Boost](https://meta.discourse.org/u/Boost)
#### Post date: [August 4, 2020, 4:58pm UTC](https://meta.discourse.org/t/custom-emoji-dont-use-cdn-for-s3-stored-assets-in-a-few-pages/159787/7 "2020-08-04T16:58:37Z")

</div>

> [@Falco](#):
>
> That is related to [S3 CDN URL ignored when uploading into posts](https://meta.discourse.org/t/s3-cdn-url-ignored-when-uploading-into-posts/54898). Added to the original topic.

So it does. If I actually post, the emoji is shown correctly in it.

> [@Falco](#):
>
> Please report on the plugin topic as it is third party.

> [@Discourse Retort](https://meta.discourse.org/t/retort-a-reaction-style-plugin-for-discourse/35903/351):
>
> I found a problem when using S3 stored assets and a CDN. Custom emojis don’t load correctly. Instead of using the CDN URL they incorrectly directly point to the S3 storage bucket. [Custom emoji don't use CDN for S3 stored assets in a few pages - #5 by Boost](https://meta.discourse.org/t/custom-emoji-dont-use-cdn-for-s3-stored-assets-in-a-few-pages/159787/5)

> [@Falco](#):
>
> This is legit, but low are of effect as it is an admin only page.

If the fix for the retort plugin is similar to how the admin area would be fixed, I could maybe give it a shot trying to fix the plugin as the custom reaction emojis are quite widely used on my discourse instance.

---

<div class="post-metadata">

### Author: ![Boost](https://avatars.discourse-cdn.com/v4/letter/b/8e8cbc/32.png) [@Boost](https://meta.discourse.org/u/Boost)
#### Post date: [August 6, 2020, 11:42am UTC](https://meta.discourse.org/t/custom-emoji-dont-use-cdn-for-s3-stored-assets-in-a-few-pages/159787/8 "2020-08-06T11:42:21Z")

</div>

I tried fixing this myself after having a quick look.  
It seems like the issue is that the discourse JavaScript method `buildEmojiUrl` receives the storage URL instead of the CDN URL for the custom emoji. Which seems to be the same thing retort plugin also uses.  
So by fixing that, it would probably fix all of the problems, right?

After that quick look I found a place that seems to build the URLs for the custom emojis and I changed that to this:

> <https://github.com/discourse/discourse/blob/baefef2c63c300892b5c119e5c2e1cfa35636bf7/app/models/emoji.rb#L119>

I tested with rails console and that seems to fix the URLs on my production site. So I tried deploying that change there, however it didn’t work.  
After that not working I also tried to change the `EMOJI_VERSION` to 10 to try to get something updating, but that didn’t work either. When I do `launcher enter` and git log I see my commit there. I followed the approach here:

> [@Can't change repo in discourse docker](https://meta.discourse.org/t/cant-change-repo-in-discourse-docker/49376/8):
>
> In the past, I’ve done it by editing app.yml like this: hooks: after\_code: - exec: cd: $home/plugins cmd: - git clone https://github.com/discourse/docker\_manager.git - git clone https://github.com/scossar/localized-categories - git clone https://github.com/scossar/dictionary-card-onebox - exec: cd: $home cmd: # changes start here - git remote remove origin - git config --remove-section branch.ma…

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [September 5, 2020, 11:42am UTC](https://meta.discourse.org/t/custom-emoji-dont-use-cdn-for-s3-stored-assets-in-a-few-pages/159787/9 "2020-09-05T11:42:24Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
