Jump to content

Where to put the stylesheet?


Glom

Recommended Posts

It is obvious that when you make your website is straight XHTML, the master stylesheet should be external (if your site demands standardisation of styles of course). That's because it makes it easier to change.However, when using server scripting to construct pages, the link to the stylesheet could very well be in a file that is standard anyway. The scripting inserts the link into the finished page the client receives. If they can do that, why not cut out the middle man and just script in the css itself?The reason I ask is that I've been looking through some sources of php pages and I have discovered large stylesheets placed internally in the markup I have received. Until this, my instinct would be to script in the link rather than script in the css itself, but what I've seen makes me wonder if there is some reason to do it the other way.Is there?

Link to comment
Share on other sites

The reason you would want to put javascript and css in an external file is because the user would only have to download the file a single time. Each subsequent visit to the page would load that external file from the browser's cache - just like images.When you are making a site that isn't expected to receive a lot of hits, an extra 10KB of css markup doesn't make much of a difference. But when you are working on a site that gets 100,000+ hits a day, that 10KB extra turns into roughly a GB of extraneous traffic each day.

Link to comment
Share on other sites

My approach would be to use a combination of the two methods. Set up the bulk of the page using a css file which doesn't change for the entire site and include in the page the styling changes which are specific for that page. This method allows you to override the styles in the css file without creating a new css file to track and code for. They call it a 'cascade' for a reason. Just make sure the 'in-page' styles follow after the css link tag.

Link to comment
Share on other sites

My approach would be to use a combination of the two methods. Set up the bulk of the page using a css file which doesn't change for the entire site and include in the page the styling changes which are specific for that page. This method allows you to override the styles in the css file without creating a new css file to track and code for. They call it a 'cascade' for a reason. Just make sure the 'in-page' styles follow after the css link tag.
That's basically what I do now. Most styles come from the external stylesheet but the occasional page has some extra style information in the head.I was planning to continue that when I convert to php, but I was surprised to find some php sites scripting the CSS directly into the markup.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...