简体   繁体   English

使用 node.js + express.js 网站减少字体大小

[英]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.我正在一个基于 node.js + express.js 的网站上工作,使用 font-awesome 作为图标技术。

Font-awesome is locally hosted, and JS file [font-awesome.js] is 1.2 mb, although we are using 10-15 icons only. Font-awesome 是本地托管的,JS 文件 [font-awesome.js] 是 1.2 mb,尽管我们只使用了 10-15 个图标。 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.如果我打开 JS 文件,有一个名为 icons 的数组,列出所有图标的 SVG 内容。 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.存在一个 [svc-javascript-core] 包( https://fontawesome.com/how-to-use/on-the-web/advanced/svg-javascript-core ),它允许创建所需的子集。 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 ).它还提到,如果您没有使用任何工具进行摇树(我不是),您可以使用深度导入( https://fontawesome.com/how-to-use/javascript-api/other/tree - 摇晃)。

However, I don't understand,然而,我不明白,

  • Would it result in creating a new JS file containing only the subset (or can I code that myself?)它会导致创建一个仅包含子集的新 JS 文件(或者我可以自己编码吗?)
  • Would that change the way I use font-awesome in my pages?这会改变我在页面中使用 font-awesome 的方式吗?

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.您可以使用Subsetter App for Font Awesome ,它让您只选择您在网站中使用的图标。

To answer your other question: no, this would not change the way you're using Font Awesome.回答您的另一个问题:不,这不会改变您使用 Font Awesome 的方式。 Except for having to update your subset when you need new icons.除了在需要新图标时必须更新您的子集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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