Created
November 14, 2016 16:00
-
-
Save remainstheday/43a97f8c5eb864a08a58b10009a6fd2a to your computer and use it in GitHub Desktop.
Load images after the page has loaded to avoid lag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This script wrapped in a Immediately-Invoked Function Expression (IIFE) to | |
* prevent variables from leaking onto the global scope. For more information | |
* on IIFE visit the link below. | |
* @see http://en.wikipedia.org/wiki/Immediately-invoked_function_expression | |
*/ | |
(function() { | |
'use strict'; | |
// Load all images via Squarespace's Responsive ImageLoader | |
function loadAllImages() { | |
var images = document.querySelectorAll('img[data-src]' ); | |
for (var i = 0; i < images.length; i++) { | |
ImageLoader.load(images[i], {load: true}); | |
} | |
} | |
// The event subscription that loads images when the page is ready | |
document.addEventListener('DOMContentLoaded', loadAllImages); | |
// The event subscription that reloads images on resize | |
window.addEventListener('resize', loadAllImages); | |
}()); |
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Omnis maxime, esse debitis corporis dolore id officiis laborum officia ducimus neque sit culpa praesentium, hic dolores voluptas nobis amet et? Numquam.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is a sample comment!!!