You can avoid manual file IO operation and render the only URL to DOM and then use a JavaScript library (like svg4everybody) that handles the URL and append file content into DOM.
thank you for taking the time to answer. I want to be able to modify part of the svg tags prior to rendering, this is why I am looking for a server-side, cache-friendly solution to this.
great to hear from you. Thank you for pointing out the obvious to me! :-)
I was suspecting that there might be a better "Umbraco" way to get to the svg content apart from using the IO library, but keeping this code and caching the partial is a great idea. Thanks again.
Read svg from media library
In Umbraco 8.5, I want to include the content of image media items of type SVG directly in html markup inside of a partial view with
@Html.Raw(...)
What is the best way to retrieve the content of the media items so the data is properly cached?
This is what works for me right now:
but this seems to be not cache-friendly.
Hi
Do you want just render SVG to page's DOM?
You can avoid manual file IO operation and render the only URL to DOM and then use a JavaScript library (like svg4everybody) that handles the URL and append file content into DOM.
Dmitriy,
thank you for taking the time to answer. I want to be able to modify part of the svg tags prior to rendering, this is why I am looking for a server-side, cache-friendly solution to this.
Hi Mikael
The problem with code you use is IO library, the slowest part is reading the file from the disk.
I would recommend you just add caching to the Partial level for example, it's super easy to do with Umbraco helper Html.CachedPartial
Thanks,
Alex
Alex.
great to hear from you. Thank you for pointing out the obvious to me! :-)
I was suspecting that there might be a better "Umbraco" way to get to the svg content apart from using the IO library, but keeping this code and caching the partial is a great idea. Thanks again.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.