On page load images above the fold aren't loaded #869
tourniquet7
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Thank you for the idea. There is a lot to digest here:
I tried to convert your code for fun (without testing it!!!), but would suggest that you try to fix your problem in a different way. In case you can't start with my code: function fix() {
// you could also add some abort condition here in case we are at top
const elements = document.querySelectorAll('img.lazyload, video.lazyload');
elements.forEach(element => {
if (element.getBoundingClientRect().bottom < 0) {
lazySizes.loader.unveil(element);
}
});
}
window.addEventListener('pageshow', (e) => {
if (!e.persisted) { // or opposite please check
fix();
}
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Lazy loading images on the e-commerce sites I have worked on has greatly increased the page load speed for those pages. There is a problem however. When a user scrolls down on a page, visits another page, then hits the back button they are in the same scroll position but what they see is completely different because the images above their scroll position haven't loaded to fill up the vertical space.
I have created some jQuery that loads all lazy loading imgs, pictures, and videos above the window viewport in order to properly fill out that vertical space. This code needs to run at the end of the page before the closing body tag. It does not help if it runs after $(document).ready();
I will provide the code. It would be great if someone could translate this into vanilla javascript so this code can be included in the readme of this project for developers to use if needed.
`function fixLazyLoad() {
Beta Was this translation helpful? Give feedback.
All reactions