Skip to content

Instantly share code, notes, and snippets.

@arash16
Created December 10, 2019 13:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arash16/b75decaa13f97f6c2d1ab7cb9f455eff to your computer and use it in GitHub Desktop.
Save arash16/b75decaa13f97f6c2d1ab7cb9f455eff to your computer and use it in GitHub Desktop.
const cache = {};
export function makePlaceholder(width, height) {
const key = `${width}x${height}`;
if (!cache[key]) {
cache[key] = 'data:image/svg+xml;base64,' + window.btoa(
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}">
<rect width="${width}" height="${height}" fill="#f0f0f0"/>
</svg>`
);
}
return cache[key];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment