【问题标题】:How to optimize loading of images on web/mobile web when scrolling滚动时如何优化网络/移动网络上的图像加载
【发布时间】:2012-12-27 08:49:47
【问题描述】:

当图像加载时,我现在正在通过我的模板加载所有图像

 //For example, I will just pass the image url into the tempate when the page renders
  %div{class: "img_container <%= answer.image_scale %> <%=answer.show_image%>"}
    <% if (media_con.standard_resolution) { %>
    %a.fancy{href: "<%= media_con.standard_resolution %>"}
      %img{src: "<%=media_con.standard_resolution%>"}

我意识到这样做(尤其是当我在页面上加载许多图像时)会导致效率低下,尤其是在移动网络上。

如何仅在视图中加载图像(滚动),也许只是加载缩略图并在带有图像的视图出现时加载实际图像。

这里的任何建议表示赞赏

【问题讨论】:

    标签: image performance backbone.js load haml


    【解决方案1】:

    有许多库可以实现这一点。我个人将Lazy Load Plugin 用于jQuery (demo)。与其在模板中设置&lt;img src&gt; 属性,不如在图片的url 中设置一个名为data-original 的属性:

    %img{data-original: "<%=media_con.standard_resolution%>", src="placeholder.png"}
    

    然后在客户端代码(可能在Backbone.view.render)上初始化库:

    $("img[data-original]").lazyload();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-14
      • 2011-05-10
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 2022-09-24
      相关资源
      最近更新 更多