Today I ran into a strange thing which was - after some reconsideration - not that strange at all.
Given is an application with 2 XPages and 2 Custom Controls. Both Custom Controls bind a JS lib each (control1 binds lib1.js and control2 binds lib2.js). If you compute the "appearance" of both controls you probably would do this using the "rendered" property, just like this:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom">
<xc:control1>
<xc:this.rendered><![CDATA[#{javascript:return context.getUrlParameter("id").equals("1")}]]></xc:this.rendered>
</xc:control1>
<xc:control2>
<xc:this.rendered><![CDATA[#{javascript:return context.getUrlParameter("id").equals("2")}]]></xc:this.rendered>
</xc:control2>
</xp:view>
In this case each control is visible if an URL parameter is set so it's specific value. But that's not important here.
What you will get when opening the page (even without any parameter) is this:
Got it? No matter of how you define the URL parameter, no matter if the content of the controls is visible or not (btw the visibility works as intended) - both resources are loaded in the page. That might not be a problem then? Ohhh, it can be a problem! Imagine both libs containing special code (and maybe equally named methods in there) for each control. You will run into a hassle.
I am not sure but this might have it's origin in the phases each XPage is running through. The renderer phase is run after the loaded phase, because if you use the "loaded" property instead everything works fine:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom">
<xc:control1>
<xc:this.loaded><![CDATA[${javascript:return context.getUrlParameter("id").equals("1")}]]></xc:this.loaded>
</xc:control1>
<xc:control2>
<xc:this.loaded><![CDATA[${javascript:return context.getUrlParameter("id").equals("2")}]]></xc:this.loaded>
</xc:control2>
</xp:view>
Notice the dynamic computation of the properties with $ instead of #. You are not allowed to use # in that context, but it's ok.
Now the JS resources are also computed depending on the visibility of the control itself:
This was new to me so maybe you'll find that helpful.
Update
Brad Balassaitis posted a similar article regarding resources - but used in a theme. It's also a good read!