peterbe / mincss

Tool for finding out which CSS selectors you're NOT using.
https://peterbe.github.io/mincss/
BSD 3-Clause "New" or "Revised" License
855 stars 92 forks source link

Remove unused @font-face #49

Open igitur opened 6 years ago

igitur commented 6 years ago

Hi

Great tool. It works great except that it doesn't remove unused CSS items, e.g.

@font-face {
  font-family: 'Lato';
  font-style: normal;
  font-weight: 400;
  src: local('Lato Regular'), local('Lato-Regular'), url(data:font/woff;base64,d09GR... <snip/> ...AisA) format('woff');
}

As you can see, the font data is encoded and embedded, which makes the spreadsheets massive (blame https://github.com/grammarly !).

peterbe commented 6 years ago

But if your minimal CSS needs something like body { font-family: 'Lato Regular'} how is it supposed to know what the font is?

igitur commented 6 years ago

Not sure I understand your question, but if the CSS needs the font, then it shouldn't be removed. Only unused fonts should be removed.

peterbe commented 6 years ago

Right, so to know the answer to that you'd need to open each selector block and look for font-family: 'Lato' right?

igitur commented 6 years ago

I think so. However, I don't know the CSS spec well enough to be aware of all uses of @font-face.

peterbe commented 6 years ago

My new Node based tool (will soon) support this: https://github.com/peterbe/minimalcss/issues/55 It's also based on a proper CSS parser whereas mincss depends on regular expressions.

igitur commented 6 years ago

Am I right that this should be fixed by https://github.com/peterbe/minimalcss/commit/5672b7b90f24e4f2ecd94df000585c6a6091e239 ?

peterbe commented 6 years ago

@igitur indeed!

igitur commented 6 years ago

Sidenote, how do I get mincss to print its version? One would expect something like mincss --version.

peterbe commented 6 years ago

Yeah, I would expect that too :) Maybe next time https://github.com/peterbe/mincss/commit/715a48fbdaaa180fe8cb795716345c2b71e65426