Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
Is it possible to use ECMAScript modules (ESM) in SVG documents?

Or will it be supported in future versions of browsers? I've been thinking about this and tried to read up on the topic, but I couldn't figure it out. I also tried the following (which did not work in either Chrome 96 or Safari 14):

<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" xml:space="preserve">

    <script type="module">
        import { demo } from './demo.js'

        const test = new demo();
        console.log('x', test);
    </script>

    <rect x="0" y="0" width="50" height="50" />
</svg>

Is it possible? Will it be possible? Is there a workaround?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Very basic example

customElements.define("svg-component", class extends HTMLElement{
  connectedCallback(){
    this.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" xml:space="preserve">
    <rect x="0" y="0" width="50" height="50" fill="${this.getAttribute('fill')}" />
</svg>`;
    // Your JS here
  }
});
svg-component{
  width:150px;
  display:inline-block;
}
<svg-component fill="red"></svg-component>
<svg-component fill="yellow"></svg-component>
<svg-component fill="blue"></svg-component>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!