Usually, it is added to own _addJsCss method of the module. And this method is called in the getCode method which "draws" the final content of the page. See for example template/scripts/BxBasePage class.