Introductie van vooraf gecompileerde JS-assets voor self-hosters

:mega: Discourse now publishes pre-built JavaScript assets, which will significantly speed up installation and updates, especially for servers with limited resources.


Compiling and optimizing JavaScript assets has always been one of the most resource-intensive parts of running Discourse. As our codebase and the JavaScript ecosystem have evolved, this process has become even more demanding.

In our tests, these changes reduce the asset-build time on a 1GB RAM Digital Ocean droplet from 45 minutes to just 3 minutes.

How does it work?

On every commit merged to main, a GitHub Actions workflow builds and bundles the assets into .tar.gz files (one for production, one for development). These bundles are published via GitHub releases in a dedicated repository. We ensure assets are published before any commit moves to tests-passed.

When building your own site, Discourse now checks for a matching pre-built bundle and downloads it. Plugins are then built on top. If no bundle is found or there’s an error, Discourse falls back to building from source.

Does this impact end-users?

No. Assets are still served to end-users from your own server / CDN.

Can I opt out?

Yes! If you prefer to build your own assets and have a sufficiently powerful server, set DISCOURSE_DOWNLOAD_PRE_BUILT_ASSETS: 0 in your app.yml file.

What if I’m running a forked or patched version of Discourse?

Asset bundles are named by commit hash. If you’re running a fork, no bundle will be found and assets will build from source. If your Discourse copy is patched (i.e., the git working tree isn’t clean), Discourse will not attempt to download a bundle.

What about other asset-related build steps?

Currently, this optimization applies only to core JS assets. In the future, we may expand it to some plugins and other steps like gz/brotli compression.

What about the stable branch?

Pre-built assets for the stable branch will be published starting with the next major version bump, planned for August 2025.

54 likes

Just did a rebuild of https://discourse-on-a-pi5.falco.dev/ and it took just 3 minutes and 35s, this is very impressive!

23 likes

Twee container-setup en zonder database ~8 minuten.

5 likes

Whoa :scream: :person_bowing:

I don’t have this option in my config, do I need to add it with a value of 1 so I can opt in? Or will all this just magically happen when I next update?

FYI dit is wat er gebeurt als je installatie niet aan de criteria voldoet:

I, [2025-08-01T06:43:09.560655 #1]  INFO -- : cd /var/www/discourse && su discourse -c 'bundle exec rake assets:precompile:build'
[assemble_ember_build] Node.js heap_size_limit is minder dan 2048MB. Instellen --max-old-space-size=2048 en CHEAP_SOURCE_MAPS=1
[assemble_ember_build] Geen bestaand build info bestand gevonden.
[assemble_ember_build] Git werkdirectory is niet schoon. Kan geen pre-built assets downloaden.
[assemble_ember_build] Volledige core build uitvoeren...

Ik breng enkele aanpassingen aan in config/initializers/100-sidekiq.rb in app.yml om ondersteuning toe te voegen voor een retry count op alle sidekiq jobs (wat ik vermoed de enige manier is om dit te bereiken en niet binnen een plugin? Maar kan opnieuw bekeken worden), dus ik geloof dat dit genoeg is om niet aan de criteria te voldoen …

2 likes

It’s enabled by default. You only need to specify the config if you want to opt-out.

Yeah exactly. Any kind of diff in the git repo will cause it to bail out.

Re. the sidekiq thing, if you open a topic about it, I’m sure we can work out a way to do it either from a plugin, or maybe we could introduce a new GlobalSetting for it.

4 likes

btw, a very simple way to time your builds without having to remain present at your console is the following:

time ./launcher rebuild app

(or whatever flavour of container if you aren’t using just one container)

which will report the elapsed time at the conclusion of the build :stopwatch:

11 likes

Mooie verandering. Ik krijg een

real 2m41.898s
user 0m0.372s
sys 0m0.583s

Bedankt voor je werk

4 likes

Wow Impressive has been date defined? my version is a81eaacb1c53581912519ae6574fa3523ef215dd I should wait to rebuild?

Oh nice :star_struck:

Thanks for that @merefield - can’t believe I’m only finding this out now after 7 years and several hundred cmd line rebuilds :grin:

5 likes

If you are following our standard release channel you can rebuild now and reap the benefits.

4 likes

De Enigen! dank u.

1 like

4 minutos to rebuild I did this a couple times today fully migrated! Impressive Discourse! next rebuild I’ll remind to use that beautiful command thanks all.

1 like

Maybe it’s an idea to limit this to app/assets, config/locales for core and plugins? Right now this will also cause a complete rebuild when Ruby-only (security) patches have been applied.

Ja, het is mogelijk dat we dit verder kunnen beperken. Hoewel het voor beveiligingspatches vrij gebruikelijk is dat deze ook de JS-app beïnvloeden… dus een volledige herbouw zal nog steeds nodig zijn.

2 likes

Just tried it, it’s fantastic, ~3min! What a smart and amazing feature. :star_struck:
It makes me want to install every existing plugin one by one now. :rofl:

5 likes

Echt echt, het is geweldig

Actually, I believe that would defeat it, if I understand correctly.

You see it can only use the compiled assets for the bundled core code (and this largely explains the recent decision to bundle the popular core plugins btw!)

It has to build & bundle any “unknown” plugin during build, so a lot of these would slow it down considerably.

2 likes

Updating to 3.6.0.beta1 and the prebuilt assets are not found

Fetching and extracting https://get.discourse.org/discourse-assets/3.6.0.beta1-d63a2431/production.tar.gz...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100     9  100     9    0     0     24      0 --:--:-- --:--:-- --:--:--    24
curl: (22) The requested URL returned error: 404
[assemble_ember_build] Failed to download prebuilt assets: Command failed with exit 22: curl
[assemble_ember_build] Running full core build...

2 likes

Richt je je op de beta-tag voor deze installatie?