matyunya / svelte-image

Image (pre)processing with Sharp for Svelte
719 stars 45 forks source link

Option to disabling lazy loading globally #43

Open d4h0 opened 4 years ago

d4h0 commented 4 years ago

Thanks for adding the 'lazy' prop to the Image component.

It would be great if there was a global option to disable lazy loading completely.

Or – probably even better – an option to disable lazy loading by default (so it's still possible to activate lazy loading with the 'lazy' prop for individual images).

Rich Harris (creator of Svelte) posted a very relevant tweet about this a few days ago:

https://twitter.com/Rich_Harris/status/1208040145385086982

:)

Btw., I think the 'lazy' props description would be clearer, if it was something like:

"lazy default: true - false disables lazy loading of images."

(instead of "lazy default: true Disables Waypoint.")

Maybe not everyone knows what Waypoint is.

artemjackson commented 4 years ago

@matyunya It's quite simple to achieve this via svelte <script context=module>:

<script context="module">
  let defaults = {
    lazy: true,
  };

  export function setDefaults(v) {
    defaults = v;
  }
</script>

<script>
  import Waypoint from "svelte-waypoint";

  // ...
  export let lazy = defaults.lazy;
  // ..
</script>