White_Lily Posted August 31, 2012 Share Posted August 31, 2012 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"> Quote Link to comment https://forums.phpfreaks.com/topic/267855-many-css-files-in-header/ Share on other sites More sharing options...
floridaflatlander Posted August 31, 2012 Share Posted August 31, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/267855-many-css-files-in-header/#findComment-1374281 Share on other sites More sharing options...
White_Lily Posted August 31, 2012 Author Share Posted August 31, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/267855-many-css-files-in-header/#findComment-1374283 Share on other sites More sharing options...
floridaflatlander Posted August 31, 2012 Share Posted August 31, 2012 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/ Quote Link to comment https://forums.phpfreaks.com/topic/267855-many-css-files-in-header/#findComment-1374291 Share on other sites More sharing options...
floridaflatlander Posted August 31, 2012 Share Posted August 31, 2012 Hit the wrong buton Quote Link to comment https://forums.phpfreaks.com/topic/267855-many-css-files-in-header/#findComment-1374293 Share on other sites More sharing options...
Mahngiel Posted September 1, 2012 Share Posted September 1, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/267855-many-css-files-in-header/#findComment-1374434 Share on other sites More sharing options...
matthewtbaker Posted October 5, 2012 Share Posted October 5, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/267855-many-css-files-in-header/#findComment-1382864 Share on other sites More sharing options...
mdmartiny Posted October 5, 2012 Share Posted October 5, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/267855-many-css-files-in-header/#findComment-1382865 Share on other sites More sharing options...
Darghon Posted October 22, 2012 Share Posted October 22, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/267855-many-css-files-in-header/#findComment-1386994 Share on other sites More sharing options...
matthewtbaker Posted October 26, 2012 Share Posted October 26, 2012 Perhaps mark this topic as solved? Quote Link to comment https://forums.phpfreaks.com/topic/267855-many-css-files-in-header/#findComment-1387857 Share on other sites More sharing options...
haku Posted October 31, 2012 Share Posted October 31, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/267855-many-css-files-in-header/#findComment-1388893 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.