I've achieved this in the past using this Template Library. From the documentation:
The Template library, written for the
CodeIgniter PHP-framework, is a
wrapper for CI’s View implementation.
Template is a reaction to the numerous
questions from the CI community
regarding how one would display
multiple views for one controller, and
how to embed “views within views” in a
standardized fashion. In addition,
Template provides extra Views loading
capabilities, the ability to utilize
any template parser (like Smarty), and
shortcuts for including CSS,
JavaScript, and other common elements
in your final rendered HTML.
Specifically, check out the library's additional utilities. It allows you to put something like this in your controller:
$this->template->add_js('js/YourJavascriptFile.js');
or
$this->template->add_js('alert("Hello!");', 'embed');
Echo $_scripts
in your template
(preferably in the <head>
section) to
utilize JavaScript added via this
method.
Similarly, you can do the same with your CSS:
$this->template->add_css('css/main.css');
$this->template->add_css('#logo {display: block}', 'embed', 'print');
..and simply echo $_styles
in your <head>
section.
Hope that helps.