I create a web component using my own implementation, in which the html template has links to images. However, these links only work if they are absolute or relative to the main document, which means that this component cannot be reused or transferred. In addition, it is very controversial.
I am currently adding the data-url_prefix attribute to all elements that should use images. Then, creating a shadow root for my custom item, I replaced {{URL_PREFIX}} with the value of this argument.
My decision seems very bad. I would be very happy if you would recommend something better, thanks.
I found an interesting quote at http://webcomponents.org/polyfills/html-imports/ :
POLYFILL NOTES
In imported documents, the href and src attributes in the HTML and the URL of the property in the CSS files refer to the location of the imported document, not the main document.
why does a polyfill use different logic to make a native implementation?
Web components Ideally, they should encapsulate all their dependencies, but if the web component requires an image, it should know the absolute URL of this image, which does not allow you to simply move the component in the file structure.
Say, for example, I have the following structure:
- index.html
- CSS
- Js
- web_components
- cool_web_component
- cool_web_component.html
- icon.png
If I changed it to the following:
- index.html
- CSS
- Js
- cool_web_component
- cool_web_component.html
- icon.png
I will need to change the pointer to icon.png somewhere in these files. My question is how to avoid this, or solve it in an elegant way. Also, why is the actual native implementation in conflict with the poly-regiments?
javascript html polymer custom-element web-component
Vlas bashynskyi
source share