1

I am using grunt-svgstore task to create consolidated version of svg files.

Problem statement:
I have include svg file after completion of grunt-svgstore task.

My Solution
svg-sprite.svg

<svg style="display: none;">
  <symbol viewBox="0 0 30 30" id="icon_arrow-down"><title>arrow-down</title><polygon points="24.5,7.2 15.2,17.1 5.3,7.8 2.6,10.7 15.4,22.8 27.4,10 "/></symbol>
</svg>

index.html

<link rel="import" id="svg-file" href="/images/svg-sprite.svg">

Footer section of index.html

<script type="text/javascript">
  var content = document.querySelector('link[rel="import"]').import;
  var el = content.querySelector('svg');
  document.body.insertBefore(el.cloneNode(true), document.body.firstChild);
</script>

Usage

<svg>
  <use xlink:href="#icon_arrow-down" />
</svg>

Is there any other way where I can write above code in more efficient way?

0 Answers0