brave / brave-browser

Brave browser for Android, iOS, Linux, macOS, Windows.
https://brave.com
Mozilla Public License 2.0
17.53k stars 2.27k forks source link

WebUI perf: serve fonts as separate files #2083

Open petemill opened 5 years ago

petemill commented 5 years ago

Currently, custom fonts are bundled as data URIs inside each and every JS bundle. This has the following negative impacts:

Luckily our web fonts (woff2) are split in to a large amount of files by font-name, font-weight and character set.

Ideally they would be served from the same URL across all web-uis to take advantage of the same cache, although since this is all local then I guess this is a secondary requirement.

I solved this in the android codebase by serving these assets from chrome://resources. An alternative would be to setup chrome://brave-resources to split brave's from chromium's. However, I found this to be a lot of code to copy or setup, versus adding a brave grdp. This implementation for android can be seen here: https://github.com/brave/browser-android-tabs/pull/814/commits/8aaa14521cf5eef12c95144cc34bdb3d76a1e7a2

Note that I first thought of solving this by adding the many common paths to all the font files in all webui data sources, via brave_webui_source. However the parent class of the underlying data source does not support sending the .woff2 mime type as a content-type http header. It is also difficult to modify this classes behavior since it is not a public output of the content module. So the easiest way (and probably best anyway) to solve this would be to serve from a different data source, and such a compatible one exists in chrome://resources.

petemill commented 5 years ago

Note that this is a higher priority for android, which is why I've been working on it now

petemill commented 5 years ago

After discussion with @bridiver, current plan is to create a new route at chrome://brave-resources which copies what the SharedResourcesDataSource does. This avoids creating dependencies from brave to non-public content/browser target, or vice versa.