Is it possible to reduce the size of a font-variable.woff2 file?

I have this Montserrat font variable from google fonts api, it has 9 weighs, from 100 to 900, but I only need 3 weights which are 400 500 600, after converting the tiff file to woff2, the file size is now at 120kb (it was 400kb before) which is still too large, I would like to drop the weighs and characters which I dont need to minimize the file as much as possible. I tried fontsquirrel.com, but it removes all the weighs except one…
37 Replies
Abdul Rehaman Shaikh
You can just select the 3 weights you want and combine them into a single file. There are mamy online combiners which will help you achieve this
Kevin Powell
Kevin Powell9mo ago
subsetting fonts is generally the easiest way to reduce file size (you mentioned dropping characters you odn't need, this is exactly that): https://the-sustainable.dev/a-guide-to-subsetting-fonts/
the-sustainable.dev
A guide to subsetting fonts – the-sustainable.dev
This guide can help you reduce the weight of individual font files by subsetting them, which can improve page load performance and weight.
Khoa
Khoa9mo ago
you could use a "variable" font so that the browser only has to load one font file to get all the weight not sure if variable font can be subset
clevermissfox
clevermissfox9mo ago
I would think you could just select 400, 500, 600 of Montserrat from Google fonts and download that file then optimize it?
共産主義のト二イ
I tried to subset the font-variable on frontsquirrel.com as the article mentions, but it removes all the weights except one, it keeps only the weight 100 and removes 200 - 900, I tried many settings, none of them work. I dont know, could you maybe try it and tell me if it worked for you, only if you have time of course. Have you done it before? If yes what tool did u use, I cant find anything related to it
Abdul Rehaman Shaikh
I’ll share the link with you.
共産主義のト二イ
Oh my Vietnamese brother, did you even read what I wrote? I am using the variable Font, but it contains all the weights from 100 - 900, and i only need 3 of them. I just want one file which contains the weighs and Alphabet I need to keep the file as small as possible Bro I am using the variable Font, Did you read what i wrote T_T. But i only need 3 weights, i dont want to download theme separately, i want one 1 file
Abdul Rehaman Shaikh
Yes, I read it again 😅 How did you manage to have montserrat file with variable woff2 font having size 120kb or 400kb. I just downloaded the montserrat variable font file for myself and it is 32 kb max
Abdul Rehaman Shaikh
Here is the file I downloaded
ἔρως
ἔρως9mo ago
this is a very terrible idea, but if you REALLY REALLY REALLY want to crunch the size of a font, just use the regular font weight (400) and then let the browser do its fake bolding, italics and stuff also, montserrat from google fonts only uses ~394kb while the weights you want take ~198kb * 3. just use the variable font as-is you save 2 http requests and about 200kb
Abdul Rehaman Shaikh
How are y'all generating file size more than 50kb for variables fonts?
ἔρως
ἔρως9mo ago
the trick is to read what i said ^ that explains it
Abdul Rehaman Shaikh
My question was not in that sense but in the sense that I have variables fonts with all font weights less than 50kb
ἔρως
ἔρως9mo ago
well, the font from google takes more than 50kb
Abdul Rehaman Shaikh
i uploaded montserrat font with variables fonts from google in 32kb
ἔρως
ἔρως9mo ago
google fonts gives a 4mb file with all the fonts
Abdul Rehaman Shaikh
how do y'all add fonts in your html file if you are using @font-face syntax if you are serving the font-files?
ἔρως
ἔρως9mo ago
the same way that google does
Abdul Rehaman Shaikh
For the value of src in the font-face syntax, do y'all pass the url from google fonts or the path of the font file stored locally in your folder I'm talking about the scenario when you want to serve files locally and not use @import from google fonts
ἔρως
ἔρως9mo ago
the only option, if your website can be accessed in europe in any way, shape or form, is to download the files and serve them yourself, as google violates the gdpr law by selling user data without consent
Abdul Rehaman Shaikh
Let's take this scenario, what would your font-face syntax look like ? I'm most interested in the value for src key
ἔρως
ἔρως9mo ago
literally just yoink from google, throw in my css, tweak the path and done im not going to write all the stuff manually, as different fonts have different definitions, and google does it all for me
Abdul Rehaman Shaikh
I was asking for a specific reason because when you don't rely on google fonts '@import' and serve files locally, the file size for any font-family should not be more than 50kb Also , I'm curious as to how people download .woff2 fonts from google fonts or variable woff2 fonts from google?
ἔρως
ἔρως9mo ago
it has a download button you're right, it shouldnt, but not all fonts are that optimized
Abdul Rehaman Shaikh
does that not lead to having a file size of + or - 4mb
ἔρως
ἔρως9mo ago
also, different versions will have different variable features which vary the size no, its ~398kb or something
Abdul Rehaman Shaikh
True but it should not be in mb
ἔρως
ἔρως9mo ago
i was talking about the zip filr you get from google fonts you wont use the zip file: just the 2 variable fontd fonts
Abdul Rehaman Shaikh
I'm curious if you know this way of downloading fonts: 1. Choose your font-family [ eg: Roboto from Google Fonts] 2. Click on get font button 3. Click on get embed code 4. Go to import 5. Copy the url part without the quotes and paste it in new tab 6. Copy the url from latin format of the font-weight you desire and voila you have yourself a font with that specified weight with a size less than 100kb
ἔρως
ἔρως9mo ago
yes, i know how to violate the rgpd gdor gdpr as i said, in europe, you have 3 options: 1- self-host the google fonts font family 2- use a different service that doesnt violate gdpr 3- use system fonts
Khoa
Khoa9mo ago
@Internet_Rambo137 1. Subset guide: https://barrd.dev/article/create-a-variable-font-subset-for-smaller-file-size/ 2. Limit the weight in your code, for example 300-600
@font-face {
font-family: 'Inter';
font-display: swap;
font-style: normal;
src: url('/fonts/Inter.woff2') format('woff2');
font-weight: 300 600;
}
@font-face {
font-family: 'Inter';
font-display: swap;
font-style: normal;
src: url('/fonts/Inter.woff2') format('woff2');
font-weight: 300 600;
}
barrd.dev
Create a variable font subset for smaller file size : barrd.dev
How to use the python fonttools library to reduce a fonts file size by removing elements you do not need using a technique called subsetting.
Khoa
Khoa9mo ago
- oh and make sure you only have woff2 in your project, don't bother using any file types other than woff2 - Self host your font, put it in your project, do not use Google services
共産主義のト二イ
‚font-weight to : 300 - 600‘, I still have to download the file tho ;D, the purpose is to minimize the file as much as possible, because I want to get the best google light house score! I will try your second suggestion.
Khoa
Khoa9mo ago
if you only type latin characters on your website, subset can remove other characters that aren't latin it can be a massive size reduction
共産主義のト二イ
Yes i tried subletting the variable font, but it removes all the weights except one
Khoa
Khoa9mo ago
use that python fonttools cmd thingy, it works really well on my variable Inter
共産主義のト二イ
Yes I will try Thank you my Vietnamese Brozer
Want results from more Discord servers?
Add your server