简体   繁体   中英

Reduce font-awesome size with node.js + express.js website

I am working on a website based on node.js + express.js, using font-awesome as icon technique.

Font-awesome is locally hosted, and JS file [font-awesome.js] is 1.2 mb, although we are using 10-15 icons only. Want to reduce that size.

Option I understand,

If I open JS file, there is an array named icons, listing SVG content for all icons. So, I can delete all but required ones. However, obvious issue with this option is that if I want to use another icon in future, I need edit it again. 在此处输入图片说明

Option I don't understand,

There exists an [svc-javascript-core] package ( https://fontawesome.com/how-to-use/on-the-web/advanced/svg-javascript-core ), that allows creating required subset. It also mentions that if you are not using any tool doing tree-shaking (I'm not), you can use deep-imports ( https://fontawesome.com/how-to-use/javascript-api/other/tree-shaking ).

However, I don't understand,

  • Would it result in creating a new JS file containing only the subset (or can I code that myself?)
  • Would that change the way I use font-awesome in my pages?

Any help would be appreciated.

You can use the Subsetter App for Font Awesome , which let you choose only the icons you're using in your website.

To answer your other question: no, this would not change the way you're using Font Awesome. Except for having to update your subset when you need new icons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM