Hi Florian,

It all started with OFBIZ-1319. Then somehow related we had OFBIZ-9465 and at 
some point we envisioned to use Require.js: OFBIZ-9976

Finally in trunk we use npm: OFBIZ-11960 (more with https://issues.apache.org/jira/browse/OFBIZ-11960?jql=project%20%3D%20OFBIZ%20AND%20text%20~%20%22npm%22)

I'm not sure this answer to your question. My point is we should try to load an external js dependencies with npm. But that's not always easy, as you said already...

HTH

Jacques

Le 25/05/2022 à 15:19, Florian Motteau a écrit :
Hi all,

I am currently working on replacing jGrowl (notification library) for a client 
project.

I came across the importLibrary function in OfbizUtil.js (common-theme), which loads external JS/CSS files when needed. If I understand correctly, some of the JS libraries (inputmask, elrte, datetimepicker, jquerytimer, jeditable, jgrowl) are loaded dynamically only when needed (if the page contains a UI element handled by an external library).

Is the main reason behind this mechanism is to avoid loading uneeded files ? If so, I am not sure that the cons of this approch are worth the pros, but of course I may miss something her :).

The pros :

 * avoid the initial loading of ~10 JS files that may be useless for
   the current page. However the time saved on page load is certainly
   negligeable,
 * do I miss something here ?

The cons (in my opinion) :

 * we need to specify loaded JS full paths in various places in
   OfbizUtil.js (vs raw list in Theme.xml), impacts
   readability/maintainability (IMHO), we should not have to scan
   OfbizUtils.js to upgrade a JS library,
 * it appears that we need to handle a minimal cache system, instead of
   relying on native browser cache (eg for each date input we trigger a
   library load)
 * when loading a form through ajax for example, the user may
   experience the loading time while he is in the middle of an
   interaction (vs initial page load)

To cope with a large number of JS/CSS files required, another approach could be to setup a bundler (similar to webpack for example), to produce a unique optimized file. This is not trivial though. The first step may be to switch to regular script inclusion (Theme.xml).

What do you think ?

Reply via email to