Overhead of CSS variables VS SCSS [closed] - css

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 months ago.
Improve this question
I have read many posts Like this one That talk about the similarities and the pros / cons of using SCSS $ vs using custom properites or var() in CSS.
I get all that and I understand the gist. My question is: Is there any overhead or degradation by forcing the browser to parse CSS variables, vs compiling the CSS and the browser just displaying the native css outputted by SASS.
We are starting a large scale project, and I am OK using custom features as I don't see a need for SCSS any longer since CSS introduced the usage of variables. I am just worried that this puts an unnecessary burden on the browser when we can just compile one time and the variables are parsed.
Am I being too analytical about this or is there something to placing the burden on the browser?

So there have been some tests regarding the performance of regular CSS —compiled from SCSS or otherwise— vs CSS w/ Custom Properties. I've done some myself with ~5k CSS variables on 10k+ HTML nodes. Those figures are similar to some of the other few articles I've seen. The performance delta is ~0.8% slower with custom properties. It's not 0, but insignificant for most reasonable use cases; we're talking >50ms differences.
I believe the actual performance issues come with style recalculation when changing variables via JavaScript. If you're using a variable declared on a parent, that is then changed, the browser will recalculate all of child elements using said variable. So better scoping and setProperty > inline styles (making changes to the HTML attribute) can give you better performance in that scenario.
Here's an interesting post on performance with this on Chrome, specifically: Improving CSS Custom Properties performance.

Related

CSS Internal External or Inline Style [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I am new to CSS and I wanted to know what is the best practice Internal Style or External Style or Inline Style as a beginner. Please tell me the basic difference also.
Here, you can find the differences between the three: https://www.w3schools.com/css/css_howto.asp
The most common one on regular websites are external stylesheets. It's the cleanest way because you separate your structure (HTML) from your styles (CSS). Internal CSS is not used a lot when hard coding a website, but it can be legit in some module based architectures. Inline CSS is also used a lot when you work with JavaScript to add styles to elements programmatically.
Edit: as cooskun wrote, the specificity is different between internal/external and inline. Inline get parsed at the end, so it is more specific. With internal and external it depends on which you declare last.
[Please try to Google your question before you post it, I am sure this has been asked before. I am not yet allowed to comment questions]
The first thing is the specificity. I could explain this detailed but it's better to have a look on this fancy website which explains the specificity perfectly.
CSS Specificity
The second reason is the code organization. If you prefer inline-style then you can't reuse your code and it makes the code hard to read, hard to maintain, hard to ...
My recommendation, go with external styles. When you have more experience in CSS, you will know where is the best place to use inline styles.

What are best-in-class CSS organization standards? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm always looking to learn from the best and ensure coding quality.
When it come to CSS styling within my responsive designs, my custom CSS style sheet can get a bit overwhelming. Constantly hitting ⌘ + F (Control + F) to locate my classes.
I could split sections of my classes into multiple style sheets (for example: media.css, typography.css etc...) however I believe calling into to many style sheets may jeopardise performance.
What are the best practices in keeping your CSS organised and well manageable?
Keep in mind that the file structure for production does not necessarily need to be the same as development.
Split up the files logically in development and group them together as needed for production. How the files are organized totally depends on your project. Of course, this implies that you have some sort of deployment pipeline in which to concatenate the files. This is not always feasible for small websites. There are hacky ways to glob files dynamically at runtime on the server, but that adds latency to the total request time.
One important advantage to this is reusability of common styles. You could have style libraries that are included in multiple stylesheets. When you need to change the core library, you're making the change in one place as opposed to many.

Creating different stylesheet for CSS3 seperated from main stylesheet [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
In my web project, I made an extra CSS file (for example css3.css) only for CSS3 properties. That means I separated the CSS3 code from my main CSS file (style.css). It helps me maintain the CSS3 properties for cross browser compatibility issues.
What kind of problems, if any, will this create for my website? What kind of problems, if any, will this create in terms of maintenance?
Thanks
No, because there is not a strict CSS2 vs. CSS3 separation, plus it would be a nightmare to maintain.
You want to address different browser vendors with post-processors like Autoprefixer for instance.
Or target different IE version via conditional comments.
On top of that, you should deliver a single, minified CSS file of your app, rather than many separate ones [unless you have good reasons for the split, e.g. loading a separate theme for mobile devices on slow connections].

About separated CSS files [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have a website, and its separated between sections, my question is:
Is it a good pratice to separate the css files for each section?
Ps.: I have a 'global' css stylesheet.
What is it you mean by sections?
General practice (as far as I know) is to have one global style sheet to style the entire look of the site.
From there you can use combinations of minimal inline styling if needed and perhaps other style sheets for specific "plugin" like objects or sections.
In the end it's your call. There are pros and cons to any way you approach it.
With one giant containing style sheet, maintainability can become difficult. Searching through thousands of line of code 3 months later when you need to make a minor tweak is a bit tough.
On the other side, many smaller style sheet means more external file calls from the website, which can slow load times (minimally).
My personal recommendation for using style sheets, use whatever method makes maintainability easiest. Use lots of comments and logical ordering.
For development I would say it is a good practice as it is easier to find what you are looking for faster or to point other developers to where they need to change some code. You can then bring in CSS preprocessors such as LESS and SASS to "build" your CSS for deployment only.
It depends...
If you feel that people may only visit one section of the site, you could avoid overhead by only serving the stylesheet for that section.
If a user will bounce around between the sections, they will need both stylesheets and it makes sense to merge them.
As far as best practices are concerned, there aren't any one size fits all for segmenting CSS. It is generally accepted to just try and minimize HTTP requests and file size as well as reusing code as often as possible. Other than that, you can use your best judgement.

Tool to parse and compare two CSS stylesheets [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
Does anyone know of a good tool that can parse and compare two CSS stylesheets in order to find which selectors have different styles?
I cannot use a standard diff-like tool because the two CSS files have very different layout. I need a tool that can parse and understand the CSS, then look for selectors that actually have different styles in the two stylesheets.
The only tool I've found is the CSS Comparer from Alan Hart, however it gets confused when there are styles that apply to multiple selectors.
Here's what I ended up doing, in case someone else has the same problem:
I used CSSTidy to "normalize" the two stylesheets I wanted to compare. Normalization in my case meant splitting multiple selectors and sorting selectors and properties. An online version of CSSTidy is available here.
After this, I used the CSS Comparer tool from Alan Hart to find out differences between the two stylesheets.
This did the job for my specific requirements.
I tried using CSS Compare. It seems to do exactly what you are looking for. However, it seems to have some issues with multiple selectors. The nice part is that it is command-line driven, so you can set up an automated process if you have lots of CSS files, or you can chain the CSS files together to compare them to one giant resultant SASS file. This tool will show you all the differences, including differences in the values of the classes.
What would be really nice if a tool showed you which styles overrode other styles in the same stylesheet. Many old sites have lots of baggage in this way and filtering it out would be great. Of course, an automated tool might cause issues, but at least something that generates a report like Firebug does, except for every selector and for the entire collection of CSS files, would be great. Sadly CSS Compare is not such a tool, and I don't know of one:(

Resources