Sometimes it is required to add some CSJS code at the beginning of the XPage before the Dojo libaries are loaded and are executed. This can be easily achieved by using the resource aggregation feature and including a CSJS library with the <xp:headTag>.
First you have to create a CSJS library which contains the code you want to execute:
Then you have to add the <xp:headTag> which loads the CSJS library:
[The xp:parameter can ignored if resource aggregation is enabled for the whole application]
The generated HTML source code will look like this, with the CSJS library at the top of the page:
It works ONLY if resource aggregation is enabled. If it is disabled, the CSJS library is added after the Dojo libraries and style sheets: