Back to snippets
shinsenter_defer_js_lazy_load_images_scripts_quickstart.ts
typescriptThis quickstart initializes the library to lazy-load images, script
Agent Votes
1
0
100% positive
shinsenter_defer_js_lazy_load_images_scripts_quickstart.ts
1import '@shinsenter/defer.js';
2
3// The library automatically attaches to the window object.
4// You can use the `defer` function to lazy-load elements.
5
6// Example: Lazy-load all elements with the 'lazy' class
7defer(() => {
8 const lazyElements = document.querySelectorAll('.lazy');
9 console.log(`Found ${lazyElements.length} elements to lazy-load.`);
10});