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]
7/25/2006 11:20:39 PM (Central Standard Time, UTC-06:00)
As usual - you're a wealth of really useful information and this is something I'm going to implement on all my skins in the future. What a great contribution.

Nina :-D
7/28/2006 1:04:57 PM (Central Standard Time, UTC-06:00)
Here Here. I will impliment this for all my portals.
7/28/2006 1:22:42 PM (Central Standard Time, UTC-06:00)
How would you get the admin.css link to appear below the shin and portal sheets so it can override them properly?
This will also prove useful in tweaking a design so the admin mods fit in the column but the css must appear last in the head.
7/28/2006 2:03:26 PM (Central Standard Time, UTC-06:00)
My last message didn't take...

Could this work to reduce the DNN JS files too? (current 35k which is already a third of the recommended size for a home page.)

I'm not familier enough with DNN to be able to say what would be admin only JS and what would be public.
7/28/2006 2:08:04 PM (Central Standard Time, UTC-06:00)
If you want to get it to add the css to the end of the list then change this line:

oCSS.Controls.AddAt(0, oLink) ' adds it to the first

To this:

oCSS.Controls.Add(oLink) ' adds it at the end
7/28/2006 2:12:56 PM (Central Standard Time, UTC-06:00)
You need most of the JS for the Solpart menu, but read some of my other blogs for ideas on that.

Especially this one,
http://blogs.snapsis.com/PermaLink,guid,e40942b7-06d2-4cfb-b8f3-aacb19af4323.aspx
7/28/2006 2:35:47 PM (Central Standard Time, UTC-06:00)
Re the snapis entry: while I'm not a patron of your menu mod (yet), I too use CSS only (housemenu) and would love to disable/remove all the solpart stuff. Don't really know where to start adding the tabid as suggested.

I use Blowery compression and have the view state removed so the site is really fast and we haven't really started to optimize the other css files since it is still in development.

But... that JS size bugs me and safely removing it would help on the journey to effective 60k.
7/28/2006 2:50:11 PM (Central Standard Time, UTC-06:00)
If you are looking for real speed, check out my new PageBlaster.
http://www.snapsis.com/OnlineStore/BrowseProducts/tabid/589/List/0/ProductID/9/Default.aspx

It does Dynamic Page Caching to memory and/or disk and Compression all together in one module.
7/28/2006 4:02:53 PM (Central Standard Time, UTC-06:00)
Cool.

Now a more direct question: would you provide a lite version of the DNN js files if, say, someone bought your menu system or caching tool?

L
10/10/2006 7:05:02 AM (Central Standard Time, UTC-06:00)
To remove solpart check (if you haven't already):
http://www.dnncreative.com/Tutorials/SkinningTutorials/HowtoremovetheSolpartmenufromacontainer/tabid/235/Default.aspx

John, I have one question... a stupid one, in which file do i insert the sugested code, in default.aspx or Default.aspx.vb?

10/10/2006 7:45:29 AM (Central Standard Time, UTC-06:00)

If you put it in the default.aspx file you will not have to recompile.
5/16/2007 11:18:37 AM (Central Standard Time, UTC-06:00)
Thank you, I never thought of that.
5/16/2007 11:19:10 AM (Central Standard Time, UTC-06:00)
If this works I will be your best friend.
5/16/2007 11:19:53 AM (Central Standard Time, UTC-06:00)
It is a pain when you have to recompile.
5/16/2007 11:20:21 AM (Central Standard Time, UTC-06:00)
That does speed things up a bit.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):