From the outside, if you publish javasscript and think that you are in a laptop (keep in mind that JS does not need an average laptop, you can be Atom-Hydrogen or Jupyter-Sidecar), you can use a sniper like:
require(['base/js/utils'], function(utils){ var base_url = utils.get_body_data('base-url') })
The data-base-url attribute is set in the <body> laptop.
However, this is not guaranteed. Typically, the extension should be installed in the nbextensions folder, which should automatically resolve correctly:
require.config({ ... paths: { nbextensions : '<base url>/nbextensions', kernelspecs : '<base url>/kernelspecs', ... })
Nbextension is a search path, so if you have configured the server correctly, you should not (most of the time) service yourself on custom URLs, and also do not process base_url yourself on the interface side.
source share