Are you adding the component to the component tree? In what phase are you doing that? JSF Resource handlind should take care of the resource loading for you, I'm surprised it's not working.
One possibility is to use RichFaces 4 resource optimization to load single minified CSS and JS files with resources for all components present. This way, your resources are present regardless of whether or not the specific component that called for them are present. Read up on how to do this here:
I am adding via ajax thats why it is not loading dependent resources.
when I am adding resource optimization, page is even worse. It is unable to load any css or JS.
I have added below code in web.xml, please let me know if we have to do some extra configuration.
We use the resource optimisation in the RichFaces showcase, have a look there to see if you are missing anything: