I’m trying to use @font-face to give my pages a nicer look, but I’m having some performance issues when rendering the pages (or FOUT, as they call it). After reading some blogs, it seems that part of the problem is the order of the script and style tags in the page. They say that the style tags must come before any script tag, and point out that most of the performance problems are caused by placing scripts before css. Unfortunately, when using Yii’s CClientScript.renderScriptFile and CClientScript.renderCssFile the scripts are placed first in the <head>, and then the styles. Is there any way to change this? Or what do I need to override to accomplish this?
Well, this may seem like a silly answer, but I’ve had some issues related to performance with @font-face and the reason was the font file size (almost 3.5MB)
Solved, it was really silly: I’m including the style sheet which defines the @font-face manually inside the layout’s <head>. I just had to move the <title> below the <style> which includes the @font-face. That’s it.
please, just for me to be sure i got it right: the main performance issue you have faced was caused by the order of style and title tags in the html "head" section? did i get the point?
I’m asking this because i always declare title before styles and this concept of tag’s order and performance sounds very interesting to me…(I googled the terms but found nothing)
The problem is that, if you include scripts before the stylesheet where you defined your @font-face, the browsers will delay the display of text: Gecko based browsers will render the text with the first not-@font-face font, then, when loaded, will render again with the @font-face font, causing a nice flickering screen; meanwhile, Chrome will not render text at all. If you have something like this:
Yii will include the javascripts coming from CClientScript.registerScriptFile and CClientScript.registerScript before the <title>, thus placing the <style> after the <script> tags, causing the crazy browser behavior.
The solution was siply to place <style> above <title>: