-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(assets): improve inlining svg #14815
Conversation
Run & review this pull request in StackBlitz Codeflow. |
@bluwy @sapphi-red What's your opinion on this? |
I think it's still not clear to me the cases we need to support in order to decide. For example, among these usages:
In practice I think we can only support 1,2,3,6? And if we acknowledge that, which means SVG data URIs will always be double quoted, then I guess we can get away with not encoding things like in this PR. Also, another thing we need to encode specifically is |
If the size improvement is big, I think we can say we don't support 4, 5 and skip encoding Also I think that we should skip |
Oh I didn't know about @firefoxic can you include the |
I will try to add But to be honest…It's not very clear to me why we would need to automatically inline SVG in markup or scripts. The inlining itself is needed to get rid of tens or hundreds of requests to small icon files. Icons are additional decoration to interface text, and it's logical to see them in styles. But in markup, it would be good to leave SVG only in the form of logos, charts, and other vector illustrations, as these are usually quite large files and there are not many of them. In scripts, too, it would be better to leave paths to files without encoding them. And if you need to work dynamically from scripts with icons in styles, it would be better to work with custom properties where icons are automatically encoded in styles. Based on this, I personally would like to be able to disable all SVG inlining except for icons in styles. I used to use postcss-url, and with this built-in feature I wanted to finally switch to LightningCSS. Maybe I'm old-fashioned in this approach. But if inlining was only in CSS, we wouldn't have to encode whitespace. And I've never encountered But yeah, this is all just my personal opinion. |
Being used in CSS doesn't mean it doesn't contain some specific tag. This is not because most people will use it only for icons that everyone will and we need to handle this. |
I apologize for the delay. I see that from the discussion above, ignoring All that remains is to not encode the What about |
Doesn't have any update? In my case, I also have spent a bit time for debugging due to just omitting double quote. below: // First my try: wrong
<div style={{ mask: `url(${dataUrlForSvg})` }} />
// By chance, I write double quote: correct
<div style={{ mask: `url("${dataUrlForSvg}")` }} /> I didn't even know i should write double quote so I set
I think Vite need to support 1~6. Otherwise, It's a bit confusing in the real use case. |
Description
All major browser engines do not need to encode
>
and<
characters.It's also easy to remove all whitespaces between tags before encoding whitespaces.
Both changes allow you to slightly reduce the amount of data in the output.
Additional context
Based on discussion
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).