How to know the path of a WebResource inside a Javascript Webresource

Hi people!

Somebody knows how to know the path of a Javascript Webresource-file inside another Javascript Webresource-file in a custom plugin?

Currently I have a javascript file that uses “dynamic load” in a script tag

var script = document.createElement(“script”);
script.src = “https://mraddon.github.io/xxx/bookmarklet.js”;
//Probably must be something like this? script.src = “/s/{build num/{system counter}/{plugin version}/_/download/resources/plugin.key:module.key/js/bookmarklet.js”;
document.body.appendChild(script);
document.body.removeChild(script);

Many thanks for the help!

@raulpelaez I don’t think this is a very suitable way of working with static resources in Atlassian apps. Is there a specific reason why you want to dynamically load this resource?

Hi remie,

Thanks for the response and yes I have a reason for this (because the target javascript code must be loaded once someone click in a button, and this code is veryyyy large because show Dialog-windows with options). The javascript file is in the same place like the javascript file that place the button.

It’s possible to do this?
Regards

@raulpelaez the problem is that your are dealing with the bundling & compression logic of Jira. As such it is more difficult to assume the location of the script. If you are sure that the other script is in the same location you should be able to load the file using a relative path as javascript/css files use their own path as base from which relative paths are resolved. Another option would be to disable compression/bundling for the add-on and add your own minification / bundling on build time (for instance, using webpack). That will also allow you to use webpack lazy loading features.

2 Likes

Thanks @remie !
The relative paths doesn’t work between javascript files, but probably with webpack and lazy loading can be possible!
I will try this: atlassian-webresource-webpack-plugin - npm
Thanks again!