Including .js and .css files clientside or serverside, performance?

Discussion in 'HTML & Website Design' started by Kendothpro, Apr 29, 2006.

  1. #1
    Tonight a simple question came to my mind:

    Why would I use:
    <link rel="stylesheet" href="style.css" type="text/css" /> (which gives an overhead for 1 more http request) when I can simply embed the code in the page using php ala:

    include('style.css'); (apparently faster since there's no http request from the browser)

    Both are editable in one place, yet everybody uses the first option, could anybody explain why?

    I'm thinking about caching but from my experiments css files don't seem to be cached, and if they're embedded in the page they can be ZLIB compressed, whereas in .css files they're not!
     
    Kendothpro, Apr 29, 2006 IP
    Smyrl likes this.
  2. forum-index.com

    forum-index.com Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    include with php is the same embed in the page.

    If you know anything about SEO then must you know using <link rel="stylesheet" href="style.css" type="text/css" /> its better for Search Engines.

    Because if Searchenginespiders dont love to large pages. Spiders want to read content, content, content. Not css or Js code. This is not relevant for your page.

    For this reason it's better linking to a css or js file. Yoru source code is clean and searhcengine robots can easily read your sourcecode.

    Mike
     
    forum-index.com, Apr 29, 2006 IP
  3. Kendothpro

    Kendothpro Well-Known Member

    Messages:
    574
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Hmmm yep you're right, I didn't think about seo...
    any other reasons why "link"ing is better than php including?
     
    Kendothpro, Apr 29, 2006 IP
  4. forum-index.com

    forum-index.com Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    because spider or robots ignore css and js code. It can read js code. If you include it, its mean your first 200 - 400 lines on your sourcecode is only css and js code.

    Spiders dont spidering total your code if your page is large. Spiders only want content. This is the reason for SEO.
    if you linking it the spider see it and read the next line, not the linked css or js file.
     
    forum-index.com, Apr 29, 2006 IP
  5. Jean-Luc

    Jean-Luc Peon

    Messages:
    601
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #5
    In most cases, it is faster to use an external .css file. The reason is that the same .css file is generally used for all pages in a site. Rather to have to download the css information in each page, the external file allows to download the information only once:
    - When the first page is accessed, the .css file is read.
    - For the following pages, the access to the css file will return a 304 code and no download takes place.

    Jean-Luc
     
    Jean-Luc, Apr 30, 2006 IP