Inline base64 or SVG image for logo #955
Replies: 6 comments
-
One thing we could do here is to keep the current config but inline any SVG file provided, i.e. Curious if anyone can think of reasons why inlining SVGs by default would be bad? |
Beta Was this translation helpful? Give feedback.
-
The obvious coming to mind may be caching? |
Beta Was this translation helpful? Give feedback.
-
Yeah that would be why I’d avoid inlining base 64 for other formats, but usually SVG is pretty lightweight and should compress pretty well with gzip, so maybe makes sense? Our Starlight docs logo is ~8k uncompressed and example pages are ~50k uncompressed. So it’s also not nothing. Would need to test how that looks after compression. I guess by inlining you optimize first site visit, but de-optimize any future navigations which would have benefited from caching the image. A secondary benefit would be that inline SVGs behave differently — they can access document scope, so for example you could set a fill using a color-theme-responsive variable and have a single file work in light and dark mode. |
Beta Was this translation helpful? Give feedback.
-
Yeah, that's a good summary.
If I understand this correctly, isn't it already possible without inlining? For example, if I take my personal website favicon which is an SVG looking like this: <svg xmlns="http://www.w3.org/2000/svg" width="128" height="128">
<style>
@media (prefers-color-scheme: dark) {
path{
fill: #xxxxxx;
}
}
</style>
<g fill="#yyyyyy">
<path d="..." transform="..."/>
<path d="..." transform="..."/>
</g>
</svg> If I use it in my Starlight config, e.g. demo.mp4Maybe I am missing the point tho ^^ |
Beta Was this translation helpful? Give feedback.
-
I think maybe that doesn’t work in… I want to say Safari? i.e. there’s some variation in whether SVG |
Beta Was this translation helpful? Give feedback.
-
Ah damn it, you're 100% right, forgot about Safari 😢 Well, this is definitely another benefit then ^^ |
Beta Was this translation helpful? Give feedback.
-
What version of
starlight
are you using?0.7.1
What is your idea?
Inline SVG or base64 for logo.
Why is this feature necessary?
It allows the user to reduce one extra network request and speed up the loading of the site by eliminating an external image call that is displayed on all pages of the site.
Do you have examples of this feature in other projects?
No examples from other projects, but here is what it could look like:
astro.config.mjs
if
logo.inline.svg
is present, then render the SVG inline where the logo's image tag would be.If
logo.inline.base64
is present, then insert the base64 string into the imagessrc
attribute.Currently, if you assign a base64 string to the
logo.src
property, it throws an error:I'll see if I can find what's going on in the source. If I can contribute I will.
Participation
Beta Was this translation helpful? Give feedback.
All reactions