Forum Moderators: open

Message Too Old, No Replies

Include .css through client or at the server?

PHP code can read it in, or use HTML to point to it?

         

Tapolyai

2:18 am on Nov 27, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



All pages on this site is in PHP, therefore all pages are processed. Is there an advantage to refer to the external .css file through
<LINK REL=StyleSheet HREF="style.css" TYPE="text/css" MEDIA=screen>
or should I just include it in my PHP code as
<?php include "/style.css");?>

Is it faster one way or an other? Is it more proper, or better implementation? In both cases I can edit a single file.

SmallTime

3:38 am on Nov 27, 2002 (gmt 0)

10+ Year Member



If you use the link, the browser will download it once for multiple pages, whereas including it would happen every page.

gsx

9:37 am on Nov 27, 2002 (gmt 0)

10+ Year Member



I would go for a mixture of the two:
<?php include "/stylereference.html");?>

In your stylereference.html use:
<LINK REL=StyleSheet HREF="style.css" TYPE="text/css" MEDIA=screen>

It may seem long-winded and extra files, but if you decide to change the stylesheet details you will only have to change it in one place. (For example add alternative stylesheets, printing stylesheets, audio stylesheets etc... or the standard changes and you decide that you would be best to add an extra parameter or two).

RossWal

5:24 pm on Nov 27, 2002 (gmt 0)

10+ Year Member



I like that approach too gsx, though I use ASP. The common server side include allows me to move the location of global files, initialize some global js variables, and make other site-wide changes that I didn't think of when the site was being built.

indiechild

8:56 am on Nov 28, 2002 (gmt 0)

10+ Year Member



gsx, I like your idea, but the PHP pages are probably being generated from one or two templates, so I doubt there is a need for the stylereference.html include.

Of course I could be wrong :D

in any case, it's good practice to use templates and includes. Especially external CSS files, as the browser is able to cache these :)

Tapolyai

3:36 am on Nov 29, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you all. I did not think of the caching part. Indeed gsx's solutions seems the most reasonable.

Thank you!