7 comments

  • simonw6 hours ago
    &gt; The accepted practice is to not add lazy-loading to images above the fold, especially the LCP image.<p>I didn&#x27;t know that. Apparently (at least according to Claude) you shouldn&#x27;t use loading=&quot;lazy&quot; on images that you expect to always display because doing so causes them to not be loaded until the browser has determined they are definitely in the viewport, which is a minor performance regression.<p>LCP = Largest Contentful Paint, the Core Web Vitals metric for when the largest visual element finishes rendering. That&#x27;s usually the largest above-the-fold image.
    • alexandermorgan6 hours ago
      Yes but the post is explicitly about images that are initially loaded only on certain devices&#x2F;screen sizes, hence the need for conditional application of lazy loading.
  • lightningspirit5 hours ago
    I like this solution, it looks very simple and should’ve been consider as part of best practices if it works technically. However, I also think that this whole trade off is broken from the beginning, it should be part of browser’s set of rules to either decide or not it should render the image or not by default, and the decision of eagerly load an image should just an hint given by the developer as a scape hatch. The current approach forces the decision to be forcefully deferred to the application which needs to guess what’s the best approach for the current set of devices in the market which also adds a constant maintenance burden.
    • DamonHD4 hours ago
      Browsers already have an early scanner to look ahead for things that it may need to load soon, such as images, and piles of heuristics. Those heuristics are hard in part because many HTML authors don&#x27;t bother marking up their image dimensions. The lazy attribute helps avoid loading images that the author can be fairly sure will not be in the initial viewport, so is an optimisation hint to override some of those heuristics. So it saves some bandwidth and helps ensure that things above the fold are not fighting things below in the initial viewport construction. So we&#x27;re about two levels of optimisation in here, but browsers do a reasonable job when fed good img tags anyway.
  • miyuru44 minutes ago
    I dont think this works.<p>I just tested on Chrome Android via remote inspect using developer tools. It loaded the image even when the image was below the fold.
    • nchmy23 minutes ago
      likewise - it always loads the image up front.
  • bmacho6 hours ago
    &gt; Not documented anywhere (but seems to work fine in major browsers)<p>Which part of it is not documented? Putting device width dependent preloading in HTTP header? MDN says that the HTTP link header works the same way as the link element, and also that the link element a has media attribute : <a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;HTML&#x2F;Reference&#x2F;Elements&#x2F;link" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;HTML&#x2F;Reference&#x2F;...</a>
    • netol6 hours ago
      I could not find this hack documented or discussed anywhere, that&#x27;s what I meant.
      • eyelidlessness52 minutes ago
        It’s not a hack, but you may find more documentation for the equivalent preload values expressed as a &lt;link&gt; tag. There is (near) parity between that and the HTTP Link header. The values used in the article should work in HTML as well.
  • DamonHD10 hours ago
    Nice pure-declarative responsive tweak!
  • xnx2 hours ago
    Not a fan of lazy loading. My time is more valuable than bandwidth.
    • abejfehr2 hours ago
      Isn’t that why you should like it then? It saves your time because you’d get the page earlier
  • onionisafruit5 hours ago
    Is it the “min-width=1024px” in the link that causes it to not load on smaller devices?
    • masklinn1 hour ago
      Yes, it&#x27;s a media query (<a href="https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Glossary&#x2F;Media_query" rel="nofollow">https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Glossary&#x2F;Media_quer...</a>) on the &lt;link&gt;. Only if the media query passes will the link &quot;activate&quot;.
    • netol5 hours ago
      To not preload, yes