Closed ivoberger closed 3 years ago
Hmm, that sucks. We've been talking about removing it altogether, as it's also a lot of extra code to drag around.
For now, the ability to turn it off is exposed via the --browsers
switch. If you specify a set of browsers that
all support link-rel-preload
according to caniuse, it won't be included. https://github.com/Munter/subfont/blob/22d803aa1a1b39ad06a79c80f3171ba6c7625974/lib/subfont.js#L70-L74
For example: subfont --browsers 'chrome 50, firefox 88' ...
Are you talking about the extra code that ends up in the website or the extra code in the subfont
source?
I'm guessing it's about the website code since the js fallback part of the subfont
source doesn't look that complicated.
My 2c on that would be to make it an opt-in flag (can still be the browsers flag, just use something that doesn't include it by default). So basically make the default browsers list the last 3 versions of Chrome, FF, MS Edge and Safari or something like that.
After all the font loading still works without preload
, it's just a bit slower and because subset
already makes the fonts a lot smaller the impact wouldn't be that big.
2 points if you decide to keep it:
--browsers
flag totally makes sense but I know of at least 1 person who didn't think of that by themselves ;)Are you talking about the extra code that ends up in the website or the extra code in the
subfont
source?
Both, actually. It's complicating both the subfont source code and the resulting web pages (as evidenced by this bug).
I think it's time to cut it out completely. Almost all browsers support proper preload now, and the ones that don't generally don't support font loading anyway.
According to caniusedb-lite
, the intersection of supports font-loading
and not supports link-rel-preload
is:
and_qq 10.4
and_uc 12.12
baidu 7.12
firefox 78
kaios 2.5
op_mob 62
... So I really don't think it's worth it at this point.
I've opened a PR here: https://github.com/Munter/subfont/pull/147
Fixed in 6.1.0
I'd like an option to disable the JS preload fallback or at least have it changed so it only runs if the browser doesn't natively support preloading (don't know if that's possible, but I'd prefer turning it off entirely anyway). I tried the Netlify plugin for font subsetting and noticed that the JS fallback causes the font files to be loaded twice. You see it in the Dev Tools Network tab on this deploy when doing a hard refresh. It eliminates most if not all size savings gained from subsetting while adding 2 network requests and at least for my uses the native preloading is well enough supported.