typefaces icon indicating copy to clipboard operation
typefaces copied to clipboard

Implement subsetting with a webpack plugin?

Open alanhussey opened this issue 8 years ago • 11 comments

Initially I’ve just added support for the Latin version of fonts. Would love to hear ideas for how to support other languages. Perhaps additional css files e.g. require('open-sans/greek')?

Is it possible to implement subsetting via a webpack plugin? Then you could ship the whole font (which would be ideal – feels like the default behavior should be to make the whole font available).

alanhussey avatar Feb 01 '17 23:02 alanhussey

I'd rather it just work w/ normal Webpack settings instead of requiring people to need to install a specialized loader + adjust the webpack config. Also if someone is using create-react-app, they wouldn't be able to use a specialized loader.

Font files aren't large — I don't see anything wrong with shipping extra versions for different languages. And since it'd be scripted, we could ensure things are setup correctly.

Also perhaps it'd also make sense to just create additional packages e.g. open-sans-variant-greek or whatever.

KyleAMathews avatar Feb 02 '17 03:02 KyleAMathews

Ah, all good points! Although I think it makes sense to keep the languages in the same package – lodash doesn't ship a separate lodash-arrays collection.

alanhussey avatar Feb 02 '17 06:02 alanhussey

I'd be keen for separate packages because otherwise it makes it very hard to use typefaces with serviceworker caching. I don't want to put unnecessary fonts into the SW cache but can't see a way to pick out the right ones as webpack will give each font an undistinguishable hash.

Would we do something like this for subsetting? Would need to automate it obviously. https://github.com/KyleAMathews/typefaces/pull/14/commits/e8fa9af6b0711829018399dbc536d41cfd7c73ab

jeznag avatar Feb 13 '17 06:02 jeznag

For service workers & typefaces I'd just do run-time caching actually (ignore my comment on the other thread) as then you only cache the font files you're actually using.

Another option is to have a custom font-face css file that only pulls in the font files you need which would be quite doable as you could do relative links to the node_modules directory e.g. ./node_modules/typeface-lato/files/lato-latin-400.woff2.

KyleAMathews avatar Feb 13 '17 23:02 KyleAMathews

@KyleAMathews Can you actually select which font style and weight we can use in the project? I'd hate to download five different thicknesses when I just need one.

dmitrizzle avatar Feb 18 '17 12:02 dmitrizzle

Browsers have got your back! They only download the fonts that are specified for use in your CSS and there is HTML matching that CSS. Hence often font for italics don't load until the second or third page when there's some words that are italized.

KyleAMathews avatar Feb 18 '17 21:02 KyleAMathews

Browsers have got your back! They only download the fonts that are specified for use in your CSS and there is HTML matching that CSS. Hence often font for italics don't load until the second or third page when there's some words that are italized.

Hm, never thinked about it. Need to test it out... Do all browsers behave this way?

But I believe there is still an issue with non-latin fonts subsets...

ArmorDarks avatar Mar 05 '17 22:03 ArmorDarks

AFAIK yes.

On supporting other languages. We'd just need to modify the script to add support for generating font files with support for other languages as well as generating additional CSS files for each subset.

Happy to support anyone who wants to create a PR adding support for this.

KyleAMathews avatar Mar 06 '17 17:03 KyleAMathews

Not true for mobile Safari, as I found. It downloads everything... At least in my case; might be due to the way the stylesheets are loaded (I'm using styled-components)

There's also no easy way to do require() in React app (it complains that all node module stuff is out of scope)

dmitrizzle avatar Jun 10 '17 09:06 dmitrizzle

So is there some way to support other languages? (slovak,french letters) with Exo font letters like š,ž looks really bad with default font.

FilipK23 avatar Feb 28 '19 09:02 FilipK23

Is there a way to utilize other languages? For example, Google Fonts offers many Japanese fonts but when installed through NPM only the Latin characters are loaded and not the Japanese characters. See M PLUS Rounded 1c, for example.

schwigri avatar Feb 04 '20 20:02 schwigri