DotNetNuke Powered!
          
John Mitchell's (mostly DotNetNuke) Blog - Seperate your Admin & Normal CSS for faster initial load times
 Tuesday, July 25, 2006

While optomizing my site I decided to spend some time on eiting the CSS Files to make the initial visit to the site faster.

I won't bore you with all the details, but if you look in the default.css file you will notice a lot of classes that only get used if a user is logged in, and they might not even get used unless the user is an administrator.

The CSS for the Menu Actions is one example of this, and the File Manager is another.

What I decided to do was break those up into seperate files, so that the anonymous user would only need to be delivered a much smaller set of CSS.

I moved all the CSS that wasn't needed into a file called admin.css and then I inject that css file only when the user is logged in.  Here is the code to do this in your own skins:

<script runat="server">
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

if Request.IsAuthenticated then
    'add a link for the css file to the head section
    Dim oLink as HtmlGenericControl = New HtmlGenericControl("link")
    oLink.Attributes("rel") = "stylesheet"
    oLink.Attributes("type") = "text/css"
    oLink.Attributes("href") = SkinPath & "admin.css"

    Dim oCSS As Control = Me.Page.FindControl("CSS")
    If Not oCSS is Nothing Then
       oCSS.Controls.AddAt(0, oLink)
    End if
  End if
End Sub
</script>

 

7/25/2006 10:30:49 PM (Central Standard Time, UTC-06:00)  #    Comments [15]