You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pagespeed.apache.org by GitBox <gi...@apache.org> on 2019/07/04 07:58:04 UTC

[GitHub] [incubator-pagespeed-mod] oschaaf commented on issue #1899: data-srcset in img and amp-img

oschaaf commented on issue #1899: data-srcset in img and amp-img
URL: https://github.com/apache/incubator-pagespeed-mod/pull/1899#issuecomment-508381724
 
 
   @Lofesa just tested this in my machine and it works fine there as well, awesome.
   I did also try it with this modification, which worked too:
   
   ```diff
   oschaaf@burst:~/code/incubator-pagespeed-mod$ git diff
   diff --git a/net/instaweb/rewriter/image_rewrite_filter.cc b/net/instaweb/rewriter/image_rewrite_filter.cc
   index 10bfca442..8d0fa1153 100644
   --- a/net/instaweb/rewriter/image_rewrite_filter.cc
   +++ b/net/instaweb/rewriter/image_rewrite_filter.cc
   @@ -2134,18 +2134,15 @@ void ImageRewriteFilter::StartElementImpl(HtmlElement* element) {
            continue;
          }
        }
   -
        BeginRewriteImageUrl(element, attributes[i].url);
   -   
   -  
   -    HtmlElement::Attribute* srcset = element->FindAttribute(HtmlName::kSrcset);
   -    HtmlElement::Attribute* datasrcset = element->FindAttribute(HtmlName::kDataSrcset);
   -    if (srcset != nullptr) {
   -           BeginRewriteSrcSet(element, srcset);
   -    } else if (datasrcset != nullptr) {
   -           BeginRewriteSrcSet(element, datasrcset);
   -    }      
   -  
   +  }
   +
   +  HtmlElement::Attribute* srcset = element->FindAttribute(HtmlName::kSrcset);
   +  HtmlElement::Attribute* datasrcset = element->FindAttribute(HtmlName::kDataSrcset);
   +  if (srcset != nullptr) {
   +    BeginRewriteSrcSet(element, srcset);
   +  } else if (datasrcset != nullptr) {
   +    BeginRewriteSrcSet(element, datasrcset);
      }
    }
   ```
   
   That is a little bit more efficient as we won't be calling FindAttribute() in a loop. 
   It may be hypothetical, but I think this may also fix an issue if there are no image-valued attributes (because we will not enter the loop in that case)
   WDYT?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services