Jump to content

Recommended Posts

Just needing to ask - is it a bad thing to have lots of CSS files in the header?

 

 


      <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS["siteUrl"]; ?>/css/whole_design.css">
      <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS["siteUrl"]; ?>/css/navigation.css">
      <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS["siteUrl"]; ?>/css/content.css">
      <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS["siteUrl"]; ?>/css/latest.css">
      <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS["siteUrl"]; ?>/css/category.css">
      <link rel="stylesheet" type="text/css" href="<?php echo $GLOBALS["siteUrl"]; ?>/css/footer.css">

Link to comment
https://forums.phpfreaks.com/topic/267855-many-css-files-in-header/
Share on other sites

The first thing a browser does is load each one of those files along with the header for those files first each time you load a page.

I'd combine them and if possible use an if condition to include special css on certain pages.

the only reason they are like that is because when they were in one file everytime i had to work on say... the footer, id have to scroll for 10 minutes until i got to where i wanted.

 

 

Plus all thos files will be needed on almost all pages, but i will consider what you said for where they dont apply.

the only reason they are like that is because when they were in one file everytime i had to work on say... the footer, id have to scroll for 10 minutes until i got to where i wanted.

 

I know what you mean, an old wordpress theme I had was like that and the css for this forum is probably like that. Close to 4k lines

 

Study your css to see where you can cut out styles to eliminate duplicates. Also plug your site URL into these sites to get a heads up on your code. You can also direct input

 

css: http://jigsaw.w3.org/css-validator

html: http://validator.w3.org

Website Optimization: http://www.websiteoptimization.com/services/analyze/

for development what you have is fine. but when your site is in production / live you're adding HTTP requests which = bad.  The browsers don't care if you have a 20k line css file or twenty 1k line files.  It is common practice to compress all your css files (stripping white-space and such) into one css file for production sites.

  • 1 month later...

Not a problem at all. It actually makes it easier for maintenance and style changes when needed. Just make sure you don't duplicate element names or classes as this could cause issues with the styling changing while the page is loading...

 

Matt

On a site that I am working on I have several different CSS files. I have some that are general css files and more that are specified to certain pages of the site. I use a function that I had written to switch out the more specified css files based on the name of the page

  • 3 weeks later...

Not sure if it's helpfull, but I used to make a "cached" single css file according to the requested page, and add the minified cached version instead of each seperate file.

also means that you shrink the number of requests the browser has to make to load the page.

which is an overall win in speed.

Older versions of IE could not handle more than 32 (I think) CSS sheets, so if you are supporting them, then you will need to make sure you have less CSS files than that.

 

But that said, this will add a lot to your page load time, so as others have said, you should be combining these into a single file on production sites.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.