akita
akita copied to clipboard
Cache top site favicons
In #54, we decided to lazy load favicons to avoid bad image loading UX. However, an additional enhancement would be to cache the favicon images so that we don't need to load them every time we visit a site.
Suggested by @vezwork in https://github.com/esse-dev/akita/issues/54#issuecomment-747855293:
We can do image serialization (for caching) using FileReader.readAsDataURL() along with the fetch API:
async function loadImageToDataURL(url)
const response = await fetch(url);
const blob = await response.blob();
return new Promise((resolve, reject) => {
const reader = new FileReader()
reader.onloadend = () => resolve(reader.result);
reader.onerror = () => reject();
reader.readAsDataURL(blob);
});
}
reference: https://stackoverflow.com/a/20285053/5425899 "How can I convert an image into Base64 string using JavaScript?"