registerCssFile

hi guys,

I am clueless on how registerCssFile work ?

What happen to the css file after I ‘register’ it ?

Is the css file available to every page after registered ?

Why/When do I use registerCssFile instead of straight css declaration in the view or include external css ?

Thanks.

It works the same way as registering JavaScript. It gets added to an array and then added to the output then rendering a page.

Availabilyty depends on where you are registering it, for example if you register it your layout file it will be available for all pages which use this layout, if you register it for the form view file it will only be available for the pages which render the form view.

When you register your files you get much more control (for example I have a custom ClienScript which includes stylesheets and javascript files only then JavaScript is available). Or for example a widget can register a css file which will only be included only then this widget is used, so it will only be loaded then it is needed.

great thinking…

It really depends on whether or not you want it included in every page. If its included in every page that’s yet another page request that needs to be loaded from the server. If its only used on pages where its needed you’ll have a more efficient web site. Now one page request won’t change much but 5 or 10 will be noticeable especially on slower connections like cell phones or legacy land lines.

If you use registerCssFile in a view it allows you to reuse that same code elsewhere but also gives you the advantage of not including it in every page.

If you were to use inline Css in a view file, depending on if that view was being used by a widget (which if you did this it would be pretty bad since it could be written out many many times depending on the widget) your css would end up in the middle of the page and possibly not all of the elements that you would like for it to affect are affected. registerCssFile and registerCss allow you to put your css code in the head of your page.

thanks for input. I got it now.

If I have a simple setup with a single primary css file that I need in the <head> for every page, I assume a normal link element is faster as it doesn’t have to be parsed or processed by the class.