Skip to content

Performances question #48

@paztis

Description

@paztis

Hi,
I recently read this article abouts the css selectors based on regular expressions: https://github.com/CSSLint/csslint/wiki/Disallow-selectors-that-look-like-regular-expressions

It seems all the selectors [class*="..."] you use in your code cost a lot for the browser, because it needs to check all existing DomElements in the page to check if its class verify or not the regExp (even if this DomElement doesn't works at all with flexgrid).

So I'm wondering about the performances of your grid compared to another one that doesn't use your suffix management, ie instead of use a class name "grid-spaceAround-center", use a more simple "grid spaceArround center" class.

The problem for me is that your code is more readable / usable than others that's why I'm hesitant.

To improve this potential problem, i've got 3 possible solution for you.

  • instead of managing your work in the "class" attribute, your can use another data-attribute like this:
<div flexGrid="grid-spaceAround">
  <col flexGrid="col-2"></col>
</div>

The advantage of this technique is only the elements that are concerned with the flexGrid management will be impacted with the CSS RegExp tests, because others will not have the data-attribute at all.
And in term of code in your sass file, it has a very small impact, because you can create a var
$gl-attributeName: class
and inside your mixins/code replace
[class*='#{$gl-gridName}']
with
[#{$gl-attributeName}*='#{$gl-gridName}']

And with this, basically everyone will have the same usage, and advanced user can change the attribute name if they want

  • Second possibility it to start all your css by a static class name:
    instead of [class*="#{$gl-gridName}-"] { .all nesting } for example use this
    .gridlex[class*="#{$gl-gridName}-"] {...}
    With this, the browser will check the existance of the class gridlex before any Regexp test I think.

  • Last possibility is to declare all existing possibilities as static classes:
    .grid-noGutter: {} .grid-noWrap: {} .grid-center: {} .grid-noGutter-noWrap: {} .grid-noGutter-center: {} grid-noGutter-noWrap-centerd: {}
    This can be done programmatically, but generates a very big css file (and perhaps not better in term of performances due to all the existing combinations.

I've no idea how to manage a benchmark for all these solutions because it's fully linked to the rendering / painting for the browser, so I cannot test all my ideas.

Are you interested by developping one of them, that can be backward compatible with olders versions ?
I can help you if you want.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions