Skip to content
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

Strip out namespace attributes for inline SVGs #290

Open
3 tasks done
bcairns opened this issue Jun 15, 2023 · 1 comment
Open
3 tasks done

Strip out namespace attributes for inline SVGs #290

bcairns opened this issue Jun 15, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@bcairns
Copy link

bcairns commented Jun 15, 2023

Clear and concise description of the problem

Namespace attributes (xmlns and xmlns:xlink) are not needed for SVGs that are inlined in text/html documents, so they are just adding unnecessary page weight.

It would be nice if this library featured an easy config option (perhaps even enabled by default) which would strip these out automatically for inline SVG output.

Suggested solution

A stripNamespaces (or similar) boolean option available in config (I would even suggest it could be defaulted to true), which removes xmlns and xmlns:xlink attributes for inline SVG output.

Alternative

We already process our icon set using Iconify dev tools and we could strip namespaces out at this stage, but this is not an ideal solution because some icons may not be inlined. It would be better to strip out namespaces only at the point of inline usage (ie when using this plugin).

This can already be accomplished nicely in the plugin config using transform. Eg:

Icons({
    ...
    transform(svg, collection, icon) {
        return svg.replace(/ xmlns(?::xlink)?=".*?"/g, '');
    },
    ...
})

A built-in config option would just make things easier for people and see this practice more universally adopted.

Additional context

The "downside" of inlining SVGs is sending the code over and over again (vs caching an external file), this can help reduce that issue somewhat.

References:

Validations

@bcairns bcairns added the enhancement New feature or request label Jun 15, 2023
@antfu
Copy link
Member

antfu commented Jun 15, 2023

Sounds good, PR welcome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants