Does CSS's "! important" property influence site performance?

0

I'd like to know if assigning the !important property influences site performance, as I use it enough to override bootstrap for example.

    
asked by anonymous 22.06.2017 / 16:09

3 answers

2

It should not have any effect on performance actually. Viewing the Firefox CSS parser at /source/layout/style/nsCSSDataBlock.cpp # 572 I think this is the relevant routine, trying to override this CSS rule.

It seems like a simple routine to check if it's "important."

 if (aIsImportant) {
    if (!HasImportantBit(aPropID))
      changed = PR_TRUE;
    SetImportantBit(aPropID);
  } else {
    // ...

It also has comments on source / layout / style / nsCSSDataBlock.h # 219

/**
 * Transfer the state for |aPropID| (which may be a shorthand)
 * from |aFromBlock| to this block.  The property being transferred
 * is !important if |aIsImportant| is true, and should replace an
 * existing !important property regardless of its own importance
 * if |aOverrideImportant| is true.
 * 
 * ...
 */
  
  • Firefox uses a handwritten bottom-up parser. In both cases, each CSS file is parsed into a StyleSheet object, each object contains CSS rules.
  •   
  • Firefox creates style context trees that contain final values (after applying all the rules in the correct order)
  •   

    Now,youcaneasilysee,forexample,withtheObjectModeldescribedabove,theparsercanmarktherulesaffectedby!importanteasily,withoutmuchcost.Performancedegradationisnotagoodargumentagainst!important.

    However,maintenanceisablow(likeotheranswersmentioned),whichmaybeyouronlyargumentagainstthem.

      

    Note:ItriedtomaketheoriginalEnglishtranslationofStackOverflow: link

        
    22.06.2017 / 22:20
    0

    It is possible that yes, since your site will load CSS, and how much you are reading it (it will read more rules) that are being overlaid by others of which you use! important.

    Think CSS is cascading, that is if you use! important, possibly doing something "wrong"!

    Read these articles, which may help you better understand the issues you may have when using it:

    22.06.2017 / 16:14
    0

    Yes and no, of course adding a! important notation will increase the size of the code, but nothing remarkable, not execution time I believe the difference is not noticeable, but of course this is a more generic answer on the subject, in big codes may be a little different.

        
    22.06.2017 / 21:58