You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Breaking out the template's <defs> into a separate SVG file would have these advantages:
Different shapes/styles for different pages on the same site
In theory, it's more efficient to have only one set of DOM definitions instead of repeating the <defs> in every shadow DOM, but I'm not sure if shadow DOM elements have visibility to a defs in the DOM.
Both files would be more readable than the current single file
But how do you load a single <defs> for the page? You don't want to force the page to include some additional script file. It has to be done from inside BaseElement. The solution that comes to mind is:
classBaseElement{static #defsLoaded;// new static booleanconstructor(template,name){// new name argumentif(!BaseElement.#defsLoaded){fetch(`defs-${name}.svg`)// ...fall back to /html-templates.then(rsp=>{// ...fall back to /html-elementsif(rsp.ok){rsp.text.then(text=>{constparser=newDOMParser;document.insertBefore(parser.parseFromString(text),document.body.firstElementChild);BaseElement.#defsLoaded =true;}}}).catch(err=>console.error(err.stack??err));}}}
Seems like a decent idea to me, but I'm not hurrying to implement it.
The same could be done with the template's <style>, but probably best to put it in this same SVG file instead of fetching a separate CSS file.
The text was updated successfully, but these errors were encountered:
Breaking out the template's
<defs>
into a separate SVG file would have these advantages:<defs>
in every shadow DOM, but I'm not sure if shadow DOM elements have visibility to adefs
in the DOM.But how do you load a single
<defs>
for the page? You don't want to force the page to include some additional script file. It has to be done from insideBaseElement
. The solution that comes to mind is:Seems like a decent idea to me, but I'm not hurrying to implement it.
The same could be done with the template's
<style>
, but probably best to put it in this same SVG file instead of fetching a separate CSS file.The text was updated successfully, but these errors were encountered: