Javascript file load

1
0
-1

Hi,

Version 6.4.1.

I have several javascript files in my resources, and i have them called from my global process pages as -script type="text/javascript" src="...js"--/script-.

The javacripts load successfully in the browser via the /aplicationResourceLocation/location = ... , but the process forms web pages sometimes appear to not take some of them (arbitrary ones) into account (it acts as if those javascript weren t load) and, other times everything works like a charm for the exactly same use case... I didnt find any reason nor pattern for the errror to occur. Any known similar issues ? It looks like dynamical javascript file load were used in BonitaSoft, i m not sure of that (so the "look likes" ), and in such case load order and synchronization is higly dependent on the Browser.

Best regards

Comments

Submitted by nicolas.tith on Mon, 01/19/2015 - 12:24

Hello,

Can you provide us a .bar file for investigations ?

Nicolas

Submitted by nsaintaubert on Fri, 01/23/2015 - 11:10

Hi,

It s easy to reproduce, generate about 15 javascript files (each ones about 50 kB), include dependencies between them: file1.js: (function( file1Library, $, undefined ) { }( window.file1Library = window.file1Library || {}, jQuery )); etc...

file2.js: if (typeof file1Library === "undefined" || ) { throw "file1Library2 requires library file1Library1"; } etc... Include them in bonitasoft portal (in adecuate order of dependencies...) and trace your browser, see how randomly appear the exceptions ...

Submitted by Sean McP on Tue, 01/27/2015 - 12:53

Why are you using 15 files for dependent code? This seems like a problem waiting to happen.

I would pull all this dependent scripts together into one file and then use a MINIFY-er to reduce the size of the file and load only this one.

I suspect the problem could be that the browser loader is simply being overwhelmed and is getting scripts out of order regardless of in sequence file order.

Submitted by nsaintaubert on Tue, 01/27/2015 - 13:39

That s what i do, but i gave you a use case that clearly reproduces the problem. The problem also appears randomly with three minified .js, but less often. Try it on firefox. It looks like dynamical javascript file load were used in BonitaSoft, i m not sure of that (so the "look likes" ), and in such case load order and synchronization is higly dependent on the Browser.

Submitted by Sean McP on Tue, 01/27/2015 - 14:32

removed as duplicate entry

Submitted by Sean McP on Tue, 01/27/2015 - 14:47

must admit I don't use FF, haven't since chrome came out.

Anyway - a quick google later I saw these two articles that may be of some help, or at least explain what is happening, otherwise I've nothing else I can provide...

the-best-way-to-load-external-javascript

Deep dive into the murky waters of script loading

Hope they help regards Seán

Submitted by nsaintaubert on Tue, 01/27/2015 - 16:39

I m not thinking about rewritting the way bonitasoft loads the javascript files ... Just thinking in using it... I already know these tecnics. Anyway, Thanks to you.

Submitted by nsaintaubert on Wed, 01/28/2015 - 13:11

Updated to bonitasoft 6.4.1. Same error observed.

1 answer

1
0
-1
This one is the BEST answer!

Hi,

The process layout is dynamically loaded. So yes, if you add scripts in them, they are dynamically added to the DOM as well.

If this is an issue, you can directly add your scripts in tomcat/bonita/client/tenants/1/work/theme/portal/BonitaForm.html. It is the entry point for the forms and it is not loaded dynamically. If you are using the subscription version, you can create a new portal looknfeel and edit this file in the looknfeel to avoid having to access the file system.

HTH Anthony

Comments

Submitted by nsaintaubert on Wed, 01/28/2015 - 16:31

@anthony.birembaut, That explains the whole thing, thanks.

Submitted by nsaintaubert on Wed, 01/28/2015 - 16:40

You might have a lot of problem for that in the future if people use widget to personalize their interface... We currently use it with slickgrid and this problem is quite perturbing, i ll try adding common libraries to the BonitaForm.html, but of sure some of them only depends on the process... Thanks.

Submitted by michel.rv on Fri, 07/17/2015 - 18:53

Same with 6.5.1 (or course, as it seems to be a 'feature').

I got exactly the same, I wanted to load SlickGrid (because Bonita's version of an Editable Grid is broken in several browsers and anyway slightly ugly), it didn't work, and then I lost several precious hours figuring out that Bonita was not loading the scripts (or other external resources) as designed in the Form customization but asynchronously.

Then I searched for a settings that would disable this asynchronous loading, no luck. Then I found this ticket. Thank you @anthony for the advice and the explanation !

Of course, the drawback of this procedure is that the customization must be applied in each installation of Bonita (development, production, next version) and is not carried with the process (.bar). But at least it should work.

Another big issue is that the URLs of the loaded resources are NO MORE processed by Bonita so that they can be found in the application's resources !

If I load SlickGrid/slick.core.js in the application's resources of the process:

=> works when it is in the a form's template as Bonita replaces the paths by the exact one including the process Id. => DOES NOT work when it is in BonitaForm.html !

The whole JS library must be put under portal/, and the URL is something like "themeResource?theme=portal&location=SlickGrid/slick.core.js".

Why people do such things ?

Notifications