Should I still bother keeping all css in one file?












6















Once upon a time I was thought by more advanced web developers (gee, when was it again? ;)) that we should avoid managing multiple CSS files and stick to one per project. It helped to improve page load speed and avoid silly mistakes when dealing with a lot overlapping CSS rules.



My question is - is this approach still valid?



Argument about page load performance doesn't seem to hold that much nowadays with awesome broadband Internet and clever web browsers with even more awesome caching capabilities.
CSS cascading can indeed be error prone, but just for inexperienced developer and having one CSS style sheet doesn't really make us bullet-proof.



I think that I would prefer to have a set of default style sheets neatly separated by components, then wire them up into one single rule by CSS @import. This would also allow me to include reset style sheet by default.



Anyone is with me?










share|improve this question


















  • 1





    You answer is SASS/LESS. Developing in modules, productive use with one minified cacheable css-file. ANd all this completely automated.

    – Christoph
    Jun 15 '12 at 9:03


















6















Once upon a time I was thought by more advanced web developers (gee, when was it again? ;)) that we should avoid managing multiple CSS files and stick to one per project. It helped to improve page load speed and avoid silly mistakes when dealing with a lot overlapping CSS rules.



My question is - is this approach still valid?



Argument about page load performance doesn't seem to hold that much nowadays with awesome broadband Internet and clever web browsers with even more awesome caching capabilities.
CSS cascading can indeed be error prone, but just for inexperienced developer and having one CSS style sheet doesn't really make us bullet-proof.



I think that I would prefer to have a set of default style sheets neatly separated by components, then wire them up into one single rule by CSS @import. This would also allow me to include reset style sheet by default.



Anyone is with me?










share|improve this question


















  • 1





    You answer is SASS/LESS. Developing in modules, productive use with one minified cacheable css-file. ANd all this completely automated.

    – Christoph
    Jun 15 '12 at 9:03
















6












6








6








Once upon a time I was thought by more advanced web developers (gee, when was it again? ;)) that we should avoid managing multiple CSS files and stick to one per project. It helped to improve page load speed and avoid silly mistakes when dealing with a lot overlapping CSS rules.



My question is - is this approach still valid?



Argument about page load performance doesn't seem to hold that much nowadays with awesome broadband Internet and clever web browsers with even more awesome caching capabilities.
CSS cascading can indeed be error prone, but just for inexperienced developer and having one CSS style sheet doesn't really make us bullet-proof.



I think that I would prefer to have a set of default style sheets neatly separated by components, then wire them up into one single rule by CSS @import. This would also allow me to include reset style sheet by default.



Anyone is with me?










share|improve this question














Once upon a time I was thought by more advanced web developers (gee, when was it again? ;)) that we should avoid managing multiple CSS files and stick to one per project. It helped to improve page load speed and avoid silly mistakes when dealing with a lot overlapping CSS rules.



My question is - is this approach still valid?



Argument about page load performance doesn't seem to hold that much nowadays with awesome broadband Internet and clever web browsers with even more awesome caching capabilities.
CSS cascading can indeed be error prone, but just for inexperienced developer and having one CSS style sheet doesn't really make us bullet-proof.



I think that I would prefer to have a set of default style sheets neatly separated by components, then wire them up into one single rule by CSS @import. This would also allow me to include reset style sheet by default.



Anyone is with me?







css optimization






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jun 15 '12 at 8:55









ŁukaszBachmanŁukaszBachman

29.7k85766




29.7k85766








  • 1





    You answer is SASS/LESS. Developing in modules, productive use with one minified cacheable css-file. ANd all this completely automated.

    – Christoph
    Jun 15 '12 at 9:03
















  • 1





    You answer is SASS/LESS. Developing in modules, productive use with one minified cacheable css-file. ANd all this completely automated.

    – Christoph
    Jun 15 '12 at 9:03










1




1





You answer is SASS/LESS. Developing in modules, productive use with one minified cacheable css-file. ANd all this completely automated.

– Christoph
Jun 15 '12 at 9:03







You answer is SASS/LESS. Developing in modules, productive use with one minified cacheable css-file. ANd all this completely automated.

– Christoph
Jun 15 '12 at 9:03














4 Answers
4






active

oldest

votes


















6














It's not about bandwidth speed but number of http requests, this makes a lot of sense for a mobile connection.



However the approach of having different css files to keep the project modular is solid, as it helps you keeping your css organized the way you want it without having all the code in one file only. Then you can benefit of css preprocessors / minifiers to concatenate and compress all your css files in a single one for production.



this article http://www.igvita.com/2012/06/14/debunking-responsive-css-performance-myths/



has a paragraph about mobile that explains well why this is a good practice:




you are much better off downloading all of the CSS content in one shot over the initial, warmed up connection. By doing so, you will also help the user extend their battery life. If there is one optimization to be made here then it is simply: concatenate and compress.







share|improve this answer





















  • 1





    I would add that the number of different http requests is also important server-side. For example Apache in his standard configuration creates a thread for each new request.

    – maxdec
    Jun 15 '12 at 9:04











  • Mobile! Good tip, I think I missed that argument totally.

    – ŁukaszBachman
    Jun 15 '12 at 9:04











  • good call @Double, +1

    – Luca
    Jun 15 '12 at 9:05



















1














Yes, that approach is still valid. There are dozens of articles about load optimization out there, but the general idea is as follows




Less files = less http requests made to server = better load performance




Main thing that changed over time is that now there are many tools that support merging multiple files into single at runtime. So you have separate stylesheets for better organization, debugging at development time, and those tools merge, minify and set correct caching headers at production.






share|improve this answer































    0














    I agree with you, I find no reason to keep only a single css sheet anymore, nowadays, I do exactly what you just stated, separation by component, along with lazy loading :) (php if statements etc).






    share|improve this answer































      0














      I separate stuff with comments. For example divs goes to /* Divs start*/ div#somediv /* Divs end*/ /* Animations start*/ /* Animations end*/. For me this is easier than merging different css files once i've completed the project






      share|improve this answer























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f11047507%2fshould-i-still-bother-keeping-all-css-in-one-file%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        6














        It's not about bandwidth speed but number of http requests, this makes a lot of sense for a mobile connection.



        However the approach of having different css files to keep the project modular is solid, as it helps you keeping your css organized the way you want it without having all the code in one file only. Then you can benefit of css preprocessors / minifiers to concatenate and compress all your css files in a single one for production.



        this article http://www.igvita.com/2012/06/14/debunking-responsive-css-performance-myths/



        has a paragraph about mobile that explains well why this is a good practice:




        you are much better off downloading all of the CSS content in one shot over the initial, warmed up connection. By doing so, you will also help the user extend their battery life. If there is one optimization to be made here then it is simply: concatenate and compress.







        share|improve this answer





















        • 1





          I would add that the number of different http requests is also important server-side. For example Apache in his standard configuration creates a thread for each new request.

          – maxdec
          Jun 15 '12 at 9:04











        • Mobile! Good tip, I think I missed that argument totally.

          – ŁukaszBachman
          Jun 15 '12 at 9:04











        • good call @Double, +1

          – Luca
          Jun 15 '12 at 9:05
















        6














        It's not about bandwidth speed but number of http requests, this makes a lot of sense for a mobile connection.



        However the approach of having different css files to keep the project modular is solid, as it helps you keeping your css organized the way you want it without having all the code in one file only. Then you can benefit of css preprocessors / minifiers to concatenate and compress all your css files in a single one for production.



        this article http://www.igvita.com/2012/06/14/debunking-responsive-css-performance-myths/



        has a paragraph about mobile that explains well why this is a good practice:




        you are much better off downloading all of the CSS content in one shot over the initial, warmed up connection. By doing so, you will also help the user extend their battery life. If there is one optimization to be made here then it is simply: concatenate and compress.







        share|improve this answer





















        • 1





          I would add that the number of different http requests is also important server-side. For example Apache in his standard configuration creates a thread for each new request.

          – maxdec
          Jun 15 '12 at 9:04











        • Mobile! Good tip, I think I missed that argument totally.

          – ŁukaszBachman
          Jun 15 '12 at 9:04











        • good call @Double, +1

          – Luca
          Jun 15 '12 at 9:05














        6












        6








        6







        It's not about bandwidth speed but number of http requests, this makes a lot of sense for a mobile connection.



        However the approach of having different css files to keep the project modular is solid, as it helps you keeping your css organized the way you want it without having all the code in one file only. Then you can benefit of css preprocessors / minifiers to concatenate and compress all your css files in a single one for production.



        this article http://www.igvita.com/2012/06/14/debunking-responsive-css-performance-myths/



        has a paragraph about mobile that explains well why this is a good practice:




        you are much better off downloading all of the CSS content in one shot over the initial, warmed up connection. By doing so, you will also help the user extend their battery life. If there is one optimization to be made here then it is simply: concatenate and compress.







        share|improve this answer















        It's not about bandwidth speed but number of http requests, this makes a lot of sense for a mobile connection.



        However the approach of having different css files to keep the project modular is solid, as it helps you keeping your css organized the way you want it without having all the code in one file only. Then you can benefit of css preprocessors / minifiers to concatenate and compress all your css files in a single one for production.



        this article http://www.igvita.com/2012/06/14/debunking-responsive-css-performance-myths/



        has a paragraph about mobile that explains well why this is a good practice:




        you are much better off downloading all of the CSS content in one shot over the initial, warmed up connection. By doing so, you will also help the user extend their battery life. If there is one optimization to be made here then it is simply: concatenate and compress.








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 10 '14 at 9:50

























        answered Jun 15 '12 at 8:58









        LucaLuca

        5,69043452




        5,69043452








        • 1





          I would add that the number of different http requests is also important server-side. For example Apache in his standard configuration creates a thread for each new request.

          – maxdec
          Jun 15 '12 at 9:04











        • Mobile! Good tip, I think I missed that argument totally.

          – ŁukaszBachman
          Jun 15 '12 at 9:04











        • good call @Double, +1

          – Luca
          Jun 15 '12 at 9:05














        • 1





          I would add that the number of different http requests is also important server-side. For example Apache in his standard configuration creates a thread for each new request.

          – maxdec
          Jun 15 '12 at 9:04











        • Mobile! Good tip, I think I missed that argument totally.

          – ŁukaszBachman
          Jun 15 '12 at 9:04











        • good call @Double, +1

          – Luca
          Jun 15 '12 at 9:05








        1




        1





        I would add that the number of different http requests is also important server-side. For example Apache in his standard configuration creates a thread for each new request.

        – maxdec
        Jun 15 '12 at 9:04





        I would add that the number of different http requests is also important server-side. For example Apache in his standard configuration creates a thread for each new request.

        – maxdec
        Jun 15 '12 at 9:04













        Mobile! Good tip, I think I missed that argument totally.

        – ŁukaszBachman
        Jun 15 '12 at 9:04





        Mobile! Good tip, I think I missed that argument totally.

        – ŁukaszBachman
        Jun 15 '12 at 9:04













        good call @Double, +1

        – Luca
        Jun 15 '12 at 9:05





        good call @Double, +1

        – Luca
        Jun 15 '12 at 9:05













        1














        Yes, that approach is still valid. There are dozens of articles about load optimization out there, but the general idea is as follows




        Less files = less http requests made to server = better load performance




        Main thing that changed over time is that now there are many tools that support merging multiple files into single at runtime. So you have separate stylesheets for better organization, debugging at development time, and those tools merge, minify and set correct caching headers at production.






        share|improve this answer




























          1














          Yes, that approach is still valid. There are dozens of articles about load optimization out there, but the general idea is as follows




          Less files = less http requests made to server = better load performance




          Main thing that changed over time is that now there are many tools that support merging multiple files into single at runtime. So you have separate stylesheets for better organization, debugging at development time, and those tools merge, minify and set correct caching headers at production.






          share|improve this answer


























            1












            1








            1







            Yes, that approach is still valid. There are dozens of articles about load optimization out there, but the general idea is as follows




            Less files = less http requests made to server = better load performance




            Main thing that changed over time is that now there are many tools that support merging multiple files into single at runtime. So you have separate stylesheets for better organization, debugging at development time, and those tools merge, minify and set correct caching headers at production.






            share|improve this answer













            Yes, that approach is still valid. There are dozens of articles about load optimization out there, but the general idea is as follows




            Less files = less http requests made to server = better load performance




            Main thing that changed over time is that now there are many tools that support merging multiple files into single at runtime. So you have separate stylesheets for better organization, debugging at development time, and those tools merge, minify and set correct caching headers at production.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 15 '12 at 9:00









            archilarchil

            34k75377




            34k75377























                0














                I agree with you, I find no reason to keep only a single css sheet anymore, nowadays, I do exactly what you just stated, separation by component, along with lazy loading :) (php if statements etc).






                share|improve this answer




























                  0














                  I agree with you, I find no reason to keep only a single css sheet anymore, nowadays, I do exactly what you just stated, separation by component, along with lazy loading :) (php if statements etc).






                  share|improve this answer


























                    0












                    0








                    0







                    I agree with you, I find no reason to keep only a single css sheet anymore, nowadays, I do exactly what you just stated, separation by component, along with lazy loading :) (php if statements etc).






                    share|improve this answer













                    I agree with you, I find no reason to keep only a single css sheet anymore, nowadays, I do exactly what you just stated, separation by component, along with lazy loading :) (php if statements etc).







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jun 15 '12 at 8:58









                    RyanRyan

                    2,3561029




                    2,3561029























                        0














                        I separate stuff with comments. For example divs goes to /* Divs start*/ div#somediv /* Divs end*/ /* Animations start*/ /* Animations end*/. For me this is easier than merging different css files once i've completed the project






                        share|improve this answer




























                          0














                          I separate stuff with comments. For example divs goes to /* Divs start*/ div#somediv /* Divs end*/ /* Animations start*/ /* Animations end*/. For me this is easier than merging different css files once i've completed the project






                          share|improve this answer


























                            0












                            0








                            0







                            I separate stuff with comments. For example divs goes to /* Divs start*/ div#somediv /* Divs end*/ /* Animations start*/ /* Animations end*/. For me this is easier than merging different css files once i've completed the project






                            share|improve this answer













                            I separate stuff with comments. For example divs goes to /* Divs start*/ div#somediv /* Divs end*/ /* Animations start*/ /* Animations end*/. For me this is easier than merging different css files once i've completed the project







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 22 '18 at 19:32









                            KhaaytilKhaaytil

                            114




                            114






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f11047507%2fshould-i-still-bother-keeping-all-css-in-one-file%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Ottavio Pratesi

                                Tricia Helfer

                                15 giugno