How to ship javascript library with plugin?

I’d like to ask what is recommended way to ship javascript library with some plugin? I can load it asynchronously from external url using e.g.

Em.$.getScript('').done(function() {

But I’d prefer storing library locally. Normally I’d use vendor.js to include it and have it loaded before the plugin code, but this approach needs hacking with the Discourse core… So what is recommended way and where to add external js library to plugin? Is there some convention? Thx.

Just add the js lib at the assets folder in your plugin, or if available, as a gem dependency.


Thanks… In the assets folder will it be loaded automatically or do I need to take care of asynchronous load as quoted in previous post? I need to load library before running plugin code.

It’s loaded in the plugin-third-party file, inside the HEAD. You can use ES6 modules to require stuff.

1 Like

I asked a similar question a few days ago (Existing JS module import into ES6 plugin). The problem I have is, that I want it included server side and I have no idea on which path I should require it in ES6 modules.

Got back to you there, so we don’t pollute here.

Thanks… placing js lib in asset folder and register_asset in plugin.rb did the trick.