Devicon icon loading lacks built-in timeout or cancellation handling
0 reputation · 24 Aug 2021, 21:07 UTC
0 reputation · 24 Aug 2021, 21:07 UTC
Devicon delivers icons through CSS classes that reference a webfont or an SVG sprite. The library ships no JavaScript, so there is no internal mechanism to detect, retry, or surface network failures when the font or sprite request is cancelled or times out. Browsers simply fail to render the glyph, leaving a blank space with no console warning from Devicon itself.
Applications that depend on these icons for navigation, status badges, or branding need a reliable degradation path. Common approaches include CSS @font-face fallbacks, onerror handlers on <img> or <use> elements, or inline placeholder SVGs. However, the library documentation does not prescribe a pattern, and the sprite structure varies between the webfont and the raw SVG distribution.
What is the recommended strategy for detecting a failed Devicon asset load in a framework-agnostic way? Does the SVG sprite expose individual symbol IDs that can be targeted for per-icon fallbacks? Are there any plans to ship a lightweight loader helper or to document an official fallback pattern?
34775 reputation · 25 Aug 2021, 02:09 UTC
Devicon ships only static CSS, webfont files and SVG assets. There is no JavaScript loader, timeout or cancellation handling built into the library, and as of the 2024/2025 releases there is no official loader helper or documented fallback pattern. The SVG sprite does expose per-icon symbol IDs that can be targeted for fallbacks. Resilience must be added by the consumer.
devicon and a single SVG sprite devicon.svg containing <symbol id=\"devicon-<name>\"> entries.Because the library is static, network failures are invisible to Devicon itself. Font loading is handled by the browser’s font subsystem, and external SVG <use> references do not fire load/error events. That is why blank icons appear with no error.
document.fonts.load rejects or times out, switch to a fallback class or show a placeholder.const timeout = 3000;
const fontPromise = document.fonts.load('1em devicon');
const timer = new Promise((_,rej)=>setTimeout(()=>rej(new Error('font timeout')), timeout));
Promise.race([fontPromise, timer])
.catch(()=> document.documentElement.classList.add('devicon-failed'));Fallback CSS: .devicon-failed .devicon { visibility:hidden } and show an inline placeholder.
<use> events. Probe the sprite file itself.fetch('devicon.svg', {cache:'force-cache'}).then(r=>{
if(!r.ok) throw new Error('sprite failed');
return r.text();
}).then(svg=>{
const div=document.createElement('div'); div.innerHTML=svg; div.style.display='none';
document.body.appendChild(div);
}).catch(()=> document.documentElement.classList.add('devicon-sprite-failed'));Per-icon fallback is possible because each symbol has a stable ID, e.g. devicon-github. On sprite failure, replace <use href=\"#devicon-github\"> with an <img src=\"fallback.svg\"> or a local inline fallback symbol.
Each icon is an individual file. Classic <img onerror> works:
<img src=\"icons/devicon-github.svg\" onerror=\"this.src='fallback.svg'\" alt=\"\">document.fonts.load('1em devicon') rejects.devicon.svg with 5xx and confirm the fetch probe fails and fallback class is applied.devicon-<name> for your version.One missing diagnostic detail that changes the recommendation: are you using the webfont CSS classes, the SVG sprite with <use>, or the raw per-icon SVG files, and is the sprite hosted same-origin or cross-origin? CORS and hosting affect whether fetch-based detection is reliable.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.