How to cache SVG icons on an external CDN while avoiding FOMI? How to cache SVG icons on an external CDN while avoiding FOMI? ajax ajax

How to cache SVG icons on an external CDN while avoiding FOMI?


The closest I could get is loading an SVG in an image element and then using it like an "old-fashioned" image sprite. This, as far as I can tell, satisfies all of your constraints. The only disadvantage I can think of is that you lose the ability to modify specific parts of the SVG using CSS. This is however not one of your constraints (correct me if I'm wrong) and it is still possible to modify all of the icon, as you can see in my demo. I created a fiddle and for completeness also include a code snippet.

To emulate a CDN, I created an SVG file and uploaded it to some image hosting service. My apologies to future readers if this service is now down. The SVG file simply has all icons next to each other in it (I created a black square, circle and triangle for now). The difference with SVG sprite maps is thus that the icons are in the SVG itself, not in the defs. It should be quite easy to combine multiple SVGs in a single one, I have not looked for tools that would automate this process.

.icon {  display: inline-block;  vertical-align: top;  width: 30px; /* can be anything */  height: 30px;  background-image: url('http://imgh.us/icons_36.svg');    border: 1px solid #000; /* just to see where the icon is */}/* sizes */.icon.large {  width: 50px;  height: 50px;  background-size: 150px auto;}/* icons */.icon.circle { background-position: -30px 0; }.icon.large.circle { background-position: -50px 0; }.icon.triangle { background-position: -60px 0; }.icon.large.triangle { background-position: -100px 0; }/* styles */.icon.info {  /* based on http://stackoverflow.com/a/25524145/962603,   * but you can of course also use an SVG filter (heh) */  filter: invert(100%) sepia(100%) saturate(50000%) hue-rotate(90deg) brightness(70%);}.icon.highlight {  /* based on http://stackoverflow.com/a/25524145/962603,   * but you can of course also use an SVG filter (heh) */  filter: invert(100%) sepia(100%) saturate(10000%) hue-rotate(30deg) brightness(50%);}
<span class="icon square"></span><span class="icon circle"></span><span class="icon triangle"></span><span class="icon circle highlight"></span><span class="icon triangle large info"></span>