Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS will-not-change

Tags:

css

w3c

There is a new CSS attribute, called will-change, using you can define properties which will be changed frequently, so the browser can optimize it. For example:

.element {
    will-change: transform, opacity;
}

But what about the opposite? Are there any suggestions or working drafts for something like will-not-change? Using it would be possible to hint the browser, that that properties will never change (constants), so it can do some optimizations on it?

like image 622
Iter Ator Avatar asked Jul 11 '16 11:07

Iter Ator


People also ask

Why is CSS style not working?

Make sure the link tag is at the right place If you put the <link> tag inside another valid header tag like <title> or <script> tag, then the CSS won't work. The external style CAN be put inside the <body> tag, although it's recommended to put it in the <head> tag to load the style before the page content.

Why is my CSS not working in Chrome?

Make sure that your CSS and HTM/HTML files use the same encoding ! If your HTM/HTML files are encoded as UNICODE, your stylesheet has to be as well. IE and Edge are not fussy : stylesheets are rendered regardless of the encodings. But Chrome is totally intolerant of unmatched encodings.

How do you force new CSS?

Anytime you make changes to CSS, JavaScript and are viewing the page you've updated - you will see this concern. You can force a refresh by pressing CTRL+F5 on the browser and that will get the latest version.


1 Answers

Browsers already optimize their layout algorithms for properties that "will not change" by default. will-change is a way to opt properties in that might change (despite what the "will" in the property name might suggest) so browsers can perform the necessary optimizations beforehand for when those properties do change (from their initial value, at least).

Think of it this way: properties that aren't listed in will-change have already been optimized as "will not change", or "whether they change or not makes no meaningful difference in performance."

For example, your will-change declaration tells the browser to create a composition layer for .element elements, in the event that they need to be transformed or alpha composited, so that their rendering is hardware accelerated from the get-go. Since this will-change declaration doesn't apply to elements without this class, the browser assumes those other elements will never be transformed or alpha composited, and as such don't need this composition layer. By not creating composition layers for them, the browser has already optimized the rendering of those elements by not hardware accelerating them unnecessarily.

like image 62
BoltClock Avatar answered Oct 30 '22 22:10

BoltClock