我有大约80种习俗,即Im 进口到Svelte前端口服。 在上,它安装了滚动装置,包括打字机、Tailwind和所有现代货物。
两难是,如何在 app中添加ons。 缩略语为特殊群体,短文为XML短文,不超过2kB。
Option 1: as image assets
- Upload all the icons as
foo.svg
intopublic/assets/icons
. - Create a svelte component
<Icon type="foo />
that displays an the icon using<img src="foo.svg>
.
这种做法意味着这些术语不属于守则的一部分。
Benefits:根据需求,可通过先令代码对信标进行动态装饰。 无需将所有电线打入配方。
<>Cons: 如果有许多新信标,页面负荷就会放缓,浏览器必须排出几十个1kB文档。 用该笔照相作为全局,意味着我们需要用人工方式告诉它,以便事先打上ons。
Option 2: as part of the app build
- Use something like https://github.com/cristovao-trevisan/svelte-icon or https://github.com/codefeathers/rollup-plugin-svelte-svg to directly import each icon into code:
import Home from ./icons/home.svg ;
- Create a svelte component that selects the right imported component or SVG string and displays it.
在此,这些信标被捆绑,作为随附本身的案文。
Benefits: Icons are delivered as part of the app bundle. Caching is unnecessary. Possible to dynamically modify some of the icon code e.g. colors, viewBox, etc on load.
<>Cons: 没有必要把所有缩略语都包含在 app中,以便把时间缩短到头部。 不能不增加复杂性。 放慢速度,因为 Java文法首先需要将体格变成特殊群体,而不是仅仅装上形象。
Questions
- It seems that building icons in tthe app is a better way from this analysis, but have I missed something?
- Does the calculus change if the "icons" are detailed images that are 50-100kB instead of the tiny strings here?