Include JavaScript from view helpers

I have written a plugin that may help you. I'm not sure that I
completely understand what you want to do though. But it may help.

http://www.agilewebdevelopment.com/plugins/resource_on_demand