Loading General Resources

Hi, I’m currently using registerScriptFile and registerCssFile to register CSS and JS resources. I need 2 sets of them, one for general loading, and the other is page specific.

		$cs = Yii::app()->getClientScript();

		$cs->registerScriptFile( Yii::app()->theme->baseUrl . '/bower_components/angular/angular.min.js' );

		$cs->registerCssFile($base_url . '/bower_components/chosen/public/chosen.min.css');

The problem is, I think because the layout/main.php is loaded after the specific view is loaded, while using registerScriptFile, the files registered in individual controller will be installed BEFORE the files registered in layout/main.php.

My current solution is to load the page specific scripts in CCLIENT::POS_END, and that’s fine for scripts. But it’s not fine for CSS Files. I have a bootstrap CSS loaded that I would like to override, and currently, because the bootstrap.min.css is loaded after the page specific CSS, it’s making the task difficult. I was wondering if there is another solution for this.

Simple solution: Don’t use CClientScript for “global” assets. Just add normal <link> and <script> elements at the beginning of <head> section in main layout.

Advanced solution: Try to use packages. Dependencies can be defined between packages and CClientScript will take care of the rest.

This is exactly what I am doing right now, I have the bootstrap.min.css loaded right after title, and yet, the individual CSS loaded in the controller is being moved before this CSS.

Move the <link> element that loads bootstrap.min.css above <title>. CSS files registered via CClientScript will be placed after right before <title>.