This example shows a map viewer that takes advantage of a lazy source. In this case, the capabilities of the remote GeoServer are not loaded until you try to explicitly add a layer from that source.
The js is not minified so it is readable. See viewer-lazy.js.