Optimizing Chrome Web UIs

How do I do it?

In order to build with a fast configuration, try setting these options in your GN args:

optimize_webui = true
is_debug = false

How is the code optimized?

Resource combination

HTML imports are a swell technology, but can be used is slow ways. Each import may also contain additional imports, which must be satisfied before certain things can continue (i.e. script execution may be paused).

<!-- If a.html contains more imports... --><linkrel="import"href="a.html"><!-- This script is blocked until done. --><script> startThePageUp();</script>

To reduce this latency, Chrome uses a tool created by the Polymer project named polymer-bundler. It processes a page starting from a URL entry point and inlines resources the first time they're encountered. This greatly decreases latency due to HTML imports.

<!-- Contents of a.html and all its dependencies. --><script> startThePageUp();</script>

CSS @apply to --var transformation

We also use polymer-css-build to transform CSS @apply mixins (which are not yet natively supported) into faster --css-variables. This turns something like this:

:host {--mixin-name:{color: red;display: block;};}/* In a different place */.red-thing {@apply(--mixin-name);}

into the more performant:

:host {--mixin-name_-_color: red;--mixin-name_-_display: block;}/* In a different place */.red-thing {color: var(--mixin-name_-_color);display: var(--mixin-name_-_display);}

JavaScript Minification

In order to minimize disk size, we run uglifyjs on all combined JavaScript. This reduces installer and the size of resources required to load to show a UI.

Gzip is currently set up to apply to a whole WebUI‘s data source, though it’s possible to exclude specific paths for things like dynamically generated content (i.e. many pages load translations dynamically from a path named “strings.js”).

To mark a WebUI‘s resources compressed, you’ll need to do something like: