SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2002
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Server overhead/efficiency question. link rel="stylesheet" vs <style></style>

    As my exceptionally descriptive topic suggests, I was wondering if anyone has tested the difference in server load between generating a page's css and importing it with <link rel= or inserting the full list of descriptors in the header.

    The css file must have variables of the users current skin inserted so it is not static. Normally I would assume that files included with <link rel are cached and only reloaded if a newer one exists so the former approach might save bandwidth. Is this the case when the href'd file is a php script which returns css? It seemed to me like an extra request to a php script on every single page load might have some significant effect on a high traffic site.
    Last edited by Israfel; Jan 15, 2007 at 01:42. Reason: grammar/spelling

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whether a browser caches a document from your server or not will mostly depend on the http headers that are sent with the document. php scripts by default usually dont send very cache friendly headers because output from php is so commonly dynamic and shouldnt be cached.

    you mention skins. sounds like you have a finite number of css files. consider having the html be dynamic and point to the proper static css file(or have php serve it with the headers to support caching).

    if the users can actually tweak the skins further, you could:
    put only these individual rules in the html document in a <style> block.

    or just have php dynamically create thier css, and link to thier css like
    css.php?userid=123, and of course send the proper headers since thier rules wont change between page requests. you could keep a leash on it so to speak by adding another url param, in case the user updates thier style
    css.php?userid=123&version=7
    version gets incremented when they change the style, forcing thier browser to grab a fresh copy.

    i would recomend you do some research on web caching, heres one of many places to start with
    http://www.mnot.net/cache_docs/

    get the live http headers extension for firefox if you want an easy way to view request and response headers.


    as far as overhead? sorry i wouldnt be able to quantify it. theres just too many variables. but reducing http requests should definately be a major goal, espescially unneccesary ones.

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Off Topic:

    Just musing, but that raises an interesting point. If you gzip the server output (I am thinking of doing that shortly) does it gzip the css too? - or as the OP questions - would an external style sheet .css arrive non gzpp'ed?

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2002
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the thoughts.

    Humm.. I'm still not sure about how frequently an css file referencing a php script would actually cause a request to the server. Kind of a judgement call and test down the road I guess. Right now my css has style variables inserted into it and is text in my header template.

    I'd like to clean up the template HTML by moving all of the css to a template called separately and possibly reap bandwidth and server request performance benefits from clients caching the css file. It seems that the css file would be cashed as long as the url calling it remains the same, so saving a timestamp when it's edited would do nicely.

    Since the rest of the site is constantly changing, most page caching is off the menu completely. 'Nother benefit of call to an external css-generating script is that I won't need to insert the style variables into every template to keep them available. That will cut down on some 20-30 calls to str_replace on every page load.

  5. #5
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Israfel View Post
    That will cut down on some 20-30 calls to str_replace on every page load.
    str_replace is almost free. You can call it thousands of times per pageload, without any worries. It seems from your posts today, that you're trying to optimize an application, but a bit in the dark on how to get about it. I strongly suggest that you install xdebug + wincachegrind and do some profiling of your PHP-scripts. You should never do any optimization without profiling before and after.

    On the clientside, it's important to make use of the browsers cache. If you generate your css dynamically, you should be sure to send the proper headers - otherwise the browser probably won't cache the document. Be aware that you can set things up so that the browser caches the stylesheet, but not the html-document. There's normally quite a lot to gain on performance by making sure that the browser cache auxiliaries such as images, stylesheets and javascript files. The apache module mod_expire is excellent for this.

    Install an extension such as firebug in your browser and have a look at what gets sent on each pageload, as well as how long each transfer takes. (Click the "NET" tab)

  6. #6
    SitePoint Zealot
    Join Date
    Apr 2002
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the info. I can see already that xdebug will be very useful.

  7. #7
    SitePoint Zealot
    Join Date
    Apr 2002
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone have any idea why xdebug won't work? I've added the appropriate line to php.ini but a phpinfo() call does not show anything about it (as the docs day it should). I'm using winxp sp2, apache 2 and php5.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •