arkon / ng-inline-svg

[Inactive] Angular directive for inserting an SVG file inline within an element.
https://echeung.me/ng-inline-svg/
MIT License
210 stars 88 forks source link

Caching svg symbol #133

Closed davoam closed 4 years ago

davoam commented 4 years ago

Hi! It looks like caching of svg symbols does not work. I use the following code

<div class="uwf-svg-icon"
     [onSVGLoaded]="onSvgLoaded"
     [cacheSVG]="true"
     [inlineSVG]="'/assets/images/icons-sprite/svg-symbols.svg#' + icon"></div>

My expectation is that it will first cache sprite file /assets/images/icons-sprite/svg-symbols.svg and then take svg from it, but instead it does request for each different icon value.

Is it possible to configure component in such a way to load sprite file only once?

davoam commented 4 years ago

@arkon I don't know how good is this solution, but I forked project and change this line to this

const svgUrl = (resolveSVGUrl
            ? this.getAbsoluteUrl(url)
            : url).replace(/#.+$/, '');

Please let me know your opinion. If it is ok, I'll create a PR.

So far it works well in our project and sprite file requested only once

arkon commented 4 years ago

A PR would be great!