1

I have a PHP script that has two CSS files in it's header. One of the CSS files only have about 5 short lines in it.

Is is safe to move that one into the larger CSS file? What's the point of having two separate CSS files when one is only a few lines?

6
  • 2
    "Is is safe to move that one into the larger CSS file?" — Depends on where else it is used. Commented Jan 9, 2013 at 11:18
  • "What's the point of having two separate CSS files when one is only a few lines?" — Separation of concerns. Different CSS for different pages. Etc. We can only speculate why the system you are working on is set up that way. Commented Jan 9, 2013 at 11:19
  • exactly.. if both css files are required in all your files then merging them will save bandwidth. as browser has to request only one file. :) Commented Jan 9, 2013 at 11:19
  • 1
    @mithunsatheesh true, but saving that one HTTP request is often pointless micro-optimization. Proper organization of your workbench is important, especially in an unstructured language like CSS, and having separate files are one part of it. (If you're serious about saving requests, setting up a deployment mechanism that automatically merges CSS and JSS might be worth thinking about) Commented Jan 9, 2013 at 11:20
  • 1
    @Pekka웃: i agree brother.. i just pointed out incase it matters (incase he is working on a mobile website) !! where bandwidth matters. Commented Jan 9, 2013 at 11:23

6 Answers 6

1

Yes their is a point in it. I have for example a design.css that handles all of the colors, a layout.css pure for positioning and sizes and I have a interaction.css which handles the animations etc..

  1. There is no problem in combining the CSS file as long as it doesnt affect readability.. Just keep in mind that the structure must remain:

file1.css file2.css

results in on file containing the below code in the same order:

/* content of file1.css */
/* content of file2.css */
Sign up to request clarification or add additional context in comments.

Comments

0

No point at all (in this case). You should move the few lines into another. If you have 2 separate files - there will be 2 requests to the server. You'll probably not see the difference as these are miliseconds, but it would be a "best practice" in this case.

Comments

0

In essence it helps browsers only load content relevant to the page, speeding up page load times.

There are services that can show how much of your downloaded CSS was applied to a given page.

Comments

0

There is no reason why you shouldnt move it into the same file.

You can have as few or as many CSS files as you need.

The advantage is only really when you have a huge number of styles and the CSS file gets large and unreadable. Then it makes sense to break them down. Or when you want to split them for different pages etc.

Its just an extra request to the server which seems pointless for only 5 lines.

Comments

0

Check to make sure that your PHP script does not reference the CSS file that has just a few lines in it. If it does not, then you're in the clear to merge the two. If it DOES reference it, then consider calling the shorter CSS file inside the larger CSS file like so:

@import url('/css/smaller-file.css');

If you add that to your larger CSS file, then you should be able to just have the larger CSS file in your PHP header.

Hope this helps!

Comments

0

Of course there is a point, just like there is a point in having many files of any languages to organize the content.

As having many requests is a big burden on performances, the usual solution (and mine) is to use a build script to build the version in production by concatenating all the CSS files of the directory into one. The precise way to do that depends on your building

Note that it's similar with what is done with JS files which are concatenated and minified.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.