ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

save as file / external css

January 31, 2008 1:04am

Subscribe [2]
  • #1 / Jan 31, 2008 1:04am

    Gilead Brook

    15 posts

    In an effort to improve performance on a site with a lot of stylesheets, I am saving templates as files, and pointing to them like this:

    <link rel="stylesheet" href="/styles/site_css.css" type="text/css" />

    Of course that file is actually called:

    site_css.css.php

    Am I gaining or losing anything by this approach, or even doing it right?

    Thanks.

  • #2 / Jan 31, 2008 10:46am

    Robin Sowell

    13255 posts

    You’re doing it right one way, but it doesn’t really save any processing.  However, EE does allow css files to be cached if you use {stylesheet=""} to link to your css held in an EE template.  When rendered, you’ll see a version number added to the css link, which is how new versions of the template will be indicated.

    Make sense?

  • #3 / Jan 31, 2008 11:02am

    Gilead Brook

    15 posts

    Thanks, Robin. When you say “new versions”, you mean if I edit the template, the version number is updated, which flags the stylesheet as changed, so that it’s re-rendered, and not drawn from the cache? Much appreciated.

  • #4 / Jan 31, 2008 11:06am

    Robin Sowell

    13255 posts

    Bingo!  I believe it was a 1.6 addition- prior to that, EE based css files wouldn’t be cached.  Which would add to the load.  So the version number was added as a way of ‘updating’ when a new template is saved.  (Prior to that, I tended to just put my css in as external files once a site was done.  Now I can go either way.  It is nice to have them in a template, since that’s the way I prefer to edit things.  On the flip side- not like I dink with the css much, so….)

  • #5 / Jan 31, 2008 11:08am

    Gilead Brook

    15 posts

    Thanks!

  • #6 / Jan 31, 2008 11:35am

    Mark Bowen

    12637 posts

    Just to add in my two cents worth here if I may?

    As far as are you doing it correctly then pretty much yes. There are a couple of other things you could specify in your css link such as media and charset but what you have should work fine.

    Example
    <link rel=“stylesheet” href=“http://www.mysite.com/css/my-css.css” type=“text/css” media=“screen, projection” charset=“utf-8” />

    As to are you gaining or losing anything, I would personally say you are doing both really! 😊
    You are gaining as the file (if a really big one - which really css should try to be kept as lean as possible wherever you can) being a static file on the server will load ever so slightly faster, or at least it should do, as opposed to it being stored in the ExpressionEngine database or cache system and then being rendered to the page. Personally though I think the speed increase will probably be very very marginal though. On the other hand if you store the css inside of the ExpressionEngine templates system then you can very easily update what you have without having to open up an FTP program, open the file in an editor and then re-save.

    Pretty much up to personal taste on that one though I would think.

    Hope that helps.

    Best wishes,

    Mark

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases