What is the best Approach for CSS framework of an Enterprise Cloud application?

前端 未结 3 2187
一整个雨季
一整个雨季 2021-02-19 14:05

There are several ways to style the elements in each page, in Enterprise applications usually the CSS Framework size increased about 1 MB, and when your users a

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-19 14:43

    File sizes

    My first point would be that when dealing with an enterprise level application the actual total quantity of css when measured in megabytes is slightly less important, even for slow internet connections. It's important that the pages you load into an empty cache of a potential conversion that just clicked your pay per click ad for the first time are as tight as you can possibly make them, but for an app that a user is paying for and is intending to invest their time and effort, priming a cache every release, even with a megabyte of css is less of a problem. You could load it all last on the login page so it's all sorted while they put their credentials in.

    Furthermore, you'll have the time to investigate some other techniques, such as loading critical 'above the fold' css in it's own, optimised file first; and splitting the css files up so that the common stuff is loaded on the first page view but any page specific stuff is loaded per page, as it's visited (for the record, this can be very good for the aforementioned PPC targets).

    CCS Tricks goes into more detail here and here.

    Complexity

    One of the bigger considerations of enterprise cloud applications is the maintainability of the css. You're probably going to have a team of developers and a complex user interface. These things can quickly turn into a maintenance nightmare if the wrong decisions are made concerning the approach to css.

    It's all very well if you users can load a page in 0.1s less, but if it takes you 30mins more to make every simple css edit then you're in trouble.

    My recommendation

    You want a combination of both. You should strive for semantic, context free css selectors in order to hit maximum re-usability (and low file size) and maximum maintainability. This allows for effective file size management and effective, scalable development.

    For example:


    .blue-box

    .header-login-box

    .contact-form-submit .green-button

    bad: not semantic, or too context specific. I'm assuming that .blah pretty much falls into this category, judging by the phrase 'do this for each element'.


    .login-box

    better: easier to re-use, semantic, but still too contextual


    .box--highlighted

    .button

    .button--standout

    even better: really re-usable because of complete decoupling from page context, but still clearly semantic, making it easier to maintain.


    With the final examples you break your app UI designs down into modules which are defined and re-used wherever they are needed. It's conceivable that you may use more than one per HTML element, but you won't have ten.

    It's also OK to use utility classes, such as .pull-left in fact, Harry Roberts at CSS Wizardry, a successful consultant whose done this stuff in the wild for real clients recommends it.

    Three further avenues of investigation

    There are currently three organisational / naming strategies for scalable css architecture that try to tackle the problem, you might want to look at them in more detail:

    BEM: docs introductory article

    OOCSS: docs introductory article

    SMACSS: docs and introduction

    All three will help maximise re-usability and minimise file sizes while giving you rules to follow to keep things tight and help with new members of the team.

提交回复
热议问题