Structuring CSS Stylesheets

Daniel Glöckner daniel.gloeckner at
Mon Aug 15 13:46:05 UTC 2016


We recently came across a number of performance issues which were caused by our poor CSS.

Our stylesheet contained too many selectors, specifically too many generic selectors targeting "common" JavaFX controls (.text, .label etc.).

We found the culprits by patching the JRE, adding some statistics to SimpleSelector and CompoundSelector. I was wondering whether there are easier ways but anyway, it works ;)

We've meanwhile improved our CSS performance (by making a bunch of selectors more specific) but want to re-structure the stylesheets to be more future-proof (with even better performance ;)).

Could you quickly comment on the following idea?

Our CSS is already divided into several stylesheets (e.g. table.css, some-dialog.css etc.). 
These stylesheets are all imported via @import into a global theme.css. theme.css is then added to the scene.

We're thinking about adding the individual stylesheets only to nodes which need them, for example our UI component factory would add table.css to a TableView's list of stylesheets (tv. getStylesheets().add("/path/to/table.css"). The global theme.css would be minimal and only define colors and fonts.

What do you think about this approach? Will this work nicely with caching of CSS styles in JavaFX?

Kind regards,

More information about the openjfx-dev mailing list