I am trying to deliver an SVG response with the help of NodeJS. This SVG has a small inline JavaScript code that dynamically calculates the width of the SVG. Everything works when the APIs are called directly using the browser. But when I use these APIs in GitHub's readme (to server SVGs in readmes) it's not allowing me to run this inline JavaScript code stored in SVG.
So when I asked this why custom headers for content-security-policy not working on github question, I got to know that github doesn't allow any inline JS, and we can't override Github's Content-Security-Policy to execute JS stored in SVGs.
So now I thought of executing the inline JavaScript on the server-side to calculate the SVG width and embed that in SVG. But the problem is how to execute this svg.setAttribute("width", svg.getBBox().width);
at server side. As these SVGs are Template Literals
on the server-side.
Questions:
Is there a way to calculate the width of SVG without rendering it on the server-side?
OR
Do I have to create a virtual DOM on the server-side to load the SVG in that DOM and then calculate the width?
OR
Is there a way to do this without JavaScript?
Can anyone help me out on how to get the dynamic width of SVG on the server-side?