Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firefox 29 requests undefined URL in case of lazy loading #98

Closed
tokkonopapa opened this issue May 30, 2014 · 7 comments
Closed

Firefox 29 requests undefined URL in case of lazy loading #98

tokkonopapa opened this issue May 30, 2014 · 7 comments
Labels
Milestone

Comments

@tokkonopapa
Copy link

When lazyload is set to true, Firefox 29 fails to get naturalWidth and requests undefined URL from fallback function for IE8.
Please check http://jsfiddle.net/tokkonoPapa/ms3c6/ or http://contentloaded.com/responsive/bbc-news/ .

@thom4parisot
Copy link
Contributor

Hello @tokkonopapa,

do you have any insight on how to fix this issue?

Thank you :-)

@tokkonopapa
Copy link
Author

Hi @oncletom,
For example, the following code suppresses unnecessary HTTP request.

    getNaturalWidth = (function(){
        if (Object.prototype.hasOwnProperty.call(document.createElement('img'), 'naturalWidth')) {
            return function (image){ return image.naturalWidth;};
        }
        // IE8 and below lacks the naturalWidth property
        return function (source){
            var img = document.createElement('img');
            img.src = source.src || "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=";
            return img.width;
        };
    })();

When source.src is undefined, the object source is HTMLDivElement. I don't know why this happens.

@thom4parisot
Copy link
Contributor

It means the naturalWidth is somewhat performed while the element is not yet replaced by an image in the DOM.

I have seen such a similar error from time to time in the CI tests so I wonder if there is a ran-DOM race condition which would trigger your issue.

@tokkonopapa
Copy link
Author

Thank you for your information.

In my experience, this can be found only in Firefox. So it seems not this project concern.

Regardless of any reason, waste of HTTP request is not good for us. So I left the above temporal code for who are intersted in this topic. And I will entrust to you that this issue should be closed or still opened.

Thanks again.

@thom4parisot thom4parisot modified the milestone: 0.3.1 Oct 24, 2014
@thom4parisot
Copy link
Contributor

#104 now creates placeholders when lazyload is on. So a naturalWidth should always be available.

Let me know if you still encounter the issue when 0.3.1 is out.

@tokkonopapa
Copy link
Author

0.3.1 is fine about this issue!

@thom4parisot
Copy link
Contributor

Thanks for your feedback @tokkonopapa 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants