CDN unable to access assets from origin


“./launcher rebuild app” generates brotli-compressed asset files with file extension “”. However, when “view source” in the browser, the asset files all have extension “.br.js”. The mismatch of file names causes 404s for CDN, as a result the browser can’t download those files either.

For example, one of the asset files shows in browser “view source” as,

<link rel='preload' href='' as='script'/>

But inside the container the files actually look like this:

# ls /var/www/discourse/public/assets/locales/en-692973624e3f492c9c0634e89f74ffa930b18c27832c1c7d9ca16864c8da12ac.*

This happens when using AWS Cloudfront as the CDN provider. When CDN is disabled, it seems to work (at least for Chrome).

(Sam Saffron) #2

I am not sure this is a bug. The “flipping” only happens in an AWS environment where you configure all s3 settings via ENV and then s3 acts as an origin for assets.

If you have s3 configured via env BE SURE to set DISCOURSE_S3_CDN_URL and BE SURE to run rake s3:upload_assets, note this is a very advanced setup that I am working on now so it has to be all configured just-so.


Thanks for replying Sam.

Does rake s3:upload_assets only need to be run once, or does it need to be added to app.yml, so it runs every time ./launcher rebuild app runs?

Also what happens if both DISCOURSE_CDN_URL and DISCOURSE_S3_CDN_URL are configured via env? I’m not sure if the later will override the former, or if they serve different purposes.

(Sam Saffron) #4

It has to run every time after assets:precompile

That is supported, just use different CDNs for both URLs, some paths have to hit the app still for the origin.


Worked like a charm!

After adding a hook to run rake s3:upload_assets after assets:precompile, my DISCOURSE_S3_CDN_URL works. So now I have two CDN urls backed by different origins. Nice, and thanks again!

(Prashant Gohel) #6

I am not able to see stylesheets in my s3 bucket after running the s3:upload_assets task. I am able to see js files in s3 though.
Is there a way to upload stylesheets to s3 too and use them from cdn.

(Sam Saffron) #7

No, they have to originate from the web server, just run a second cdn for the web.