Won't fix JSON response has reverse order of JS/CSS files

Rasmus Vind

Well-known member
I can't understand how this has seemingly worked for me in the past. Anyway. I am having the following problem.

I have a page that shows up as a xenForm inside the same page, but I can also navigate to the same page in its own browser window. The weird thing is, one works and one does not.

I have tracked the problem to a call to array_reverse on the JS/CSS assets which confuses my code as I require two JS files, one being a library and one being my code.

Here is my template:
Skærmbillede 2016-11-23 19.41.34.webp

And when I load the page separately (not inside an existing page), this is what I get and expect:
Skærmbillede 2016-11-23 19.43.06.webp

However, when I load it as a xenForm, I get this:
Skærmbillede 2016-11-23 19.41.52.webp
My JS files are sent in opposite order of input.

I took a look in the source code and found this:
Skærmbillede 2016-11-23 19.42.25.webp
And did not find any place where it gets reversed back.

This is the way I render the page:
Skærmbillede 2016-11-23 20.04.50.webp

Please advice.

EDIT: I flipped the order of JS files and it's still not working. I'm starting to suspect that it does not work with multiple JS files.

EDIT: I need to look more into this. It may be a completely different matter...
 
Last edited:
I have to admit I'm not sure I understand the need for that array reverse, but even removed, array_unique sorts. Essentially, the order of the JS files is generally considered to be non-deterministic. This is very significant in your example as when the JS files are dynamically loaded, they're loaded and executed simultaneously (as they come in). As such, your code needs to handle a situation where its initial execution is triggered before other JS files are loaded; the best method here is to attach your actual activation code into the XF JS framework system which will only be triggered when everything is loaded.

As this line actually predates the 1.0 beta release and changing it wouldn't end up fixing this issue, I'm not going to change it at this time.
 
As such, your code needs to handle a situation where its initial execution is triggered before other JS files are loaded; the best method here is to attach your actual activation code into the XF JS framework system which will only be triggered when everything is loaded.
While it is not much of a problem for me, it is a bit of a pity, I think, that the form overlay and the dedicated page then have differences in behavior because of this.

As to my problem, I found out that the problem was actually the way my code was $.globalEval()'d. It seems like declarations like 'var x = ...' is not put into the global scope with this function. I stopped looking into this and found a different solution to my problem using 'window.x = ...' instead.

Thanks for getting back to me Mike, you guys rock.
 
Top Bottom