question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implementation of laziness

See original GitHub issue

Hi! I was searching for progressive enhancement approaches to lazy loading and found your answer on Stack Overflow intriguing. This looks like a more standards-compliant solution, but I think the lazy component is missing.

If I’m reading your code correctly, this script by itself —i.e. loadMedia()— would still result in the browser downloading every image on the page all at once, instead of waiting for one event or another to fire. I imagine the intended use is for developers to create their own event-listening function that would then call loadMedia('#id') whenever img#id approaches the viewport. Is this correct?

In any case, are you planning on implementing a default listener of some sort, such that loadMedia() by itself would actually result in each image loading only as viewport scrolling approaches it?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:20 (19 by maintainers)

github_iconTop GitHub Comments

2reactions
tvlercommented, Apr 13, 2016

Hi! Thanks for reaching out.

Having a loadMedia(‘scroll’) type of feature would be good, but there are so many variable things that can happen to a page to affect an image’s page height that I think developers should implement that themselves. For example if an element is resized or deleted, which causes an image’s position to change, there’s no JavaScript event for me to hook that repositioning logic into.

I think I like that this library right now is just a manual lazyloader, it keeps the code super clean. But I’ll take a look at how the major lazy loaders calculate height. If it looks pretty stable I’ll implement it for this. 👍

1reaction
tvlercommented, May 1, 2016

I’ve added a scroll option to the loadMedia function:

loadMedia (
   element,
   onload,
   scroll
)

element: CSS String | NodeList | Element

onload: Function (optional)

scroll: Boolean (optional) – loads image when visible

You can check out an example of it on the project’s new website: http://tylerdeitz.co/lazy-progressive-enhancement/

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implementing Laziness - Brown CS
The points where the implementation of a lazy language forces an expression to reduce to a value (if any) are called the strictness...
Read more >
Understand and implement laziness with examples in Scala ...
Implementing laziness in a language like JavaScript requires modifying both the point of definition and the point of use. The exception to this...
Read more >
On the design, implementation, and use of laziness in R
This paper presents a review of the design and implementation of call-by-need in R, and a data-driven study of how generations of programmers ......
Read more >
On the Design, Implementation, and Use of Laziness in R - arXiv
This paper presents a review of the design and implementation of call-by-need in R, and a data-driven study of how generations of programmers ......
Read more >
Lazy evaluation - Wikipedia
In programming language theory, lazy evaluation, or call-by-need, is an evaluation strategy which delays the evaluation of an expression until its value is ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found