querySelector
Image Lazy Loader
<img data-src="https://images.unsplash.com/photo-1494633114655-819eb91fde40?auto=format&fit=crop&w=2550&q=80&ixid=dW5zcGxhc2guY29tOzs7Ozs%3D" alt="Above it All. A photo by @anthonyintraversato on Unsplash"/>
const imgList = document.querySelectorAll('img[data-src]');
// lazy load images
Array.from(imgList).forEach(el => {
el.setAttribute('src', el.getAttribute('data-src'));
el.onload = function() {
el.removeAttribute('data-src');
};
});
const nodeList = document.querySelectorAll('myclassname');
Array.from(nodeList).forEach(el => {
if (el !== null) {
(async() => {
await import(`app/module/${el.dataset.component}`);
})();
}
});