Lazy loading

pull/8454/head
Puru Vijay 3 years ago
parent d4a7097312
commit 07b07f38e0

@ -63,9 +63,9 @@
<Supporters /> <Supporters />
{#if $theme.current === 'light'} {#if $theme.current === 'light'}
<Image src={BallsLight} alt="The Svelte logo in a ball pit" /> <Image lazy src={BallsLight} alt="The Svelte logo in a ball pit" />
{:else} {:else}
<Image src={BallsDark} alt="The Svelte logo in a ball pit" /> <Image lazy src={BallsDark} alt="The Svelte logo in a ball pit" />
{/if} {/if}
<footer> <footer>

@ -5,14 +5,20 @@
/** @type {string} */ /** @type {string} */
export let alt; export let alt;
console.log(src); export let lazy = false;
</script> </script>
<picture> <picture>
{#each Object.entries(src?.sources ?? {}) as [format, images]} {#each Object.entries(src?.sources ?? {}) as [format, images]}
<source srcset={images?.map((i) => `${i?.src} ${i?.w}w`).join(', ')} type="image/{format}" /> <source srcset={images?.map((i) => `${i?.src} ${i?.w}w`).join(', ')} type="image/{format}" />
{/each} {/each}
<img height={src.img.h} width={src.img.w} src={src?.img?.src} {alt} /> <img
loading={lazy ? 'lazy' : 'eager'}
height={src.img.h}
width={src.img.w}
src={src?.img?.src}
{alt}
/>
</picture> </picture>
<style> <style>

Loading…
Cancel
Save