You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Or we can encapsulate this component further. Finally, we are using it like
<svg-iconicon-name="icon-arrow"></svg-icon>
As you can see, the size of the script is determined by how many icons we have. If we have a big icon base, the icon code would be very large. For example, currently, we only have one icon called icon-arrow the icon code is
The gzipped file size would be more than 50kB. In the cases that we just need one or a few icons, the size of the script would be a waste and might hurt performance. So here are my thoughts.
Thoughts
Say we have a loader, it can read and analyze our source code. It might be possible to know how many icons were really used in our project and finally remove the unused icon code to reduce the size of the script. However, there might exist some situations we need to handle carefully.
Dynamic Icon Name
In this scenery, the source code would be like
<svg-iconicon-name="variable"></svg-icon>
It means that we won't be able to know what the real icon-name is before the code runs. However, we could enhance our implementation of svg-icon. For example, support a prop like icon-names to allow developers to pass the possible icon names. The demo code would be
If the loader meets any scenery it doesn't know, it can give up the tree shake function and output the original file content or throw an error to tell the developers.
The text was updated successfully, but these errors were encountered:
Say our team is maintaining an icon base using iconfont and we are using the icon with Symbol like this
So, we would get a script URL whose content is like this
And when we are using it the code would be like
Or we can encapsulate this component further. Finally, we are using it like
As you can see, the size of the script is determined by how many icons we have. If we have a big icon base, the icon code would be very large. For example, currently, we only have one icon called
icon-arrow
the icon code isIf we have 100 icons whose names are like
icon-arrow1
,icon-arrow2
......untilicon-arrow100
, the icon code would be likeThe gzipped file size would be more than 50kB. In the cases that we just need one or a few icons, the size of the script would be a waste and might hurt performance. So here are my thoughts.
Thoughts
Say we have a loader, it can read and analyze our source code. It might be possible to know how many icons were really used in our project and finally remove the unused icon code to reduce the size of the script. However, there might exist some situations we need to handle carefully.
Dynamic Icon Name
In this scenery, the source code would be like
It means that we won't be able to know what the real icon-name is before the code runs. However, we could enhance our implementation of
svg-icon
. For example, support a prop likeicon-names
to allow developers to pass the possible icon names. The demo code would beUnknow Scenerys
If the loader meets any scenery it doesn't know, it can give up the tree shake function and output the original file content or throw an error to tell the developers.
The text was updated successfully, but these errors were encountered: