Skip to content

Reduce size of webfont payload #448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 4, 2018
Merged

Conversation

msmorgan
Copy link
Contributor

@msmorgan msmorgan commented Nov 29, 2018

This brings down the size of the fonts dramatically by using woff and woff2 and splitting the fonts into Unicode subranges. The full font payload on the home page goes from approximately 3MB to less than 90kB.

The fonts.css stylesheet is now generated by the SASS compiler on app launch.

@msmorgan msmorgan changed the title Update fonts CSSS with smaller formats for Fira Sans Update fonts CSS with smaller formats for Fira Sans Nov 29, 2018
@ashleygwilliams ashleygwilliams added this to the edition-release milestone Nov 29, 2018
@ashleygwilliams ashleygwilliams self-requested a review November 29, 2018 22:48
@msmorgan
Copy link
Contributor Author

Found a typo, fixing.

@msmorgan msmorgan force-pushed the lighter-fonts branch 3 times, most recently from 8629b7f to 8a5c9cd Compare November 29, 2018 23:34
@msmorgan
Copy link
Contributor Author

Typo fixed. I had accidentally removed the font-display: block; declarations, but those are back now.

@ashleygwilliams ashleygwilliams requested review from chriskrycho and removed request for ashleygwilliams November 30, 2018 00:22
@ashleygwilliams
Copy link
Member

@chriskrycho since you are who added this - could you take a look? thanks!

@chriskrycho
Copy link
Contributor

Ah, very nice – thank you for this pr, @msmorgan! I'm a big fan of going to woff/woff2 wherever possible.

A couple notes:

  • We definitely don't need anything but woff and woff2 – even IE9 had woff support! – so we should drop the .eot files
  • The character subsetting could in principle reduce the size loaded as well… if we split the font files apart. My guess is that Google Fonts was smart enough to be doing that; we definitely aren't doing anything that fancy, so I'm good with removing those here.
  • While we're at it, we should replace the existing .ttf files with .woff and .woff2 files.

@msmorgan
Copy link
Contributor Author

@chriskrycho I copied the faces and styles directly from the Fira repository. It was last updated 3 years ago, and I suppose it was best practice at that time to use eot fonts. I'll go ahead and remove the eot fonts, as well as the ttf fonts for Fira Sans.

I looked online and could not find a woff or woff2 version of Alfa Slab One. I found some online conversion tools, but I'm not sure if the license of Alfa Slab One allows the conversion.

@msmorgan
Copy link
Contributor Author

I found a tool (font-ranger) capable of splitting the fonts into separate versions for different Unicode ranges. I ran that on all the fonts, which had the side effect of converting Alfa Slab One to woff and woff2. I generated a new version of fonts.css using sass.

@msmorgan msmorgan force-pushed the lighter-fonts branch 2 times, most recently from ca66d40 to 3f4d3a8 Compare November 30, 2018 19:35
@chriskrycho
Copy link
Contributor

Outstanding! I will re-review in a bit and test locally as well, but thank you so much for doing that!

@msmorgan
Copy link
Contributor Author

I think I'm done fiddling with this now. On the homepage the font payload is now less than 90kB.

@chriskrycho
Copy link
Contributor

That is fantastic! Thank you so much for pushing that down so far. I will test and this should be merged tomorrow!

@msmorgan
Copy link
Contributor Author

@chriskrycho If you'd like, I can squash the first few commits so the unused fonts don't end up in the version history.

@chriskrycho
Copy link
Contributor

That would be great – a nice bit of savings of download bandwidth in its own way!

The package 'font-ranger' on NPM was used to process the fonts.
@msmorgan
Copy link
Contributor Author

msmorgan commented Dec 3, 2018

@chriskrycho I've cleaned up the commit history. This should be ready to merge.

@chriskrycho
Copy link
Contributor

Perfect! I'll verify/test myself and merge by the end of the day! Thank you again; this is really outstanding.

@msmorgan msmorgan changed the title Update fonts CSS with smaller formats for Fira Sans Reduce size of webfont payload Dec 3, 2018
@chriskrycho chriskrycho merged commit 7ca2500 into rust-lang:master Dec 4, 2018
Copy link
Contributor

@chriskrycho chriskrycho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again! Merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants