“undefined” randomly appended in 1% of requested urls on my website since 12 june 2012

前端 未结 8 2171

Since 12 june 2012 11:20 TU, I see very weirds errors in my varnish/apache logs.

Sometimes, when an user has requested one page, several seconds later I see a simila

相关标签:
8条回答
  • 2020-12-02 06:23

    You have correctly established that the undefined relates to a JavaScript problem and if your site users haven't complained about seeing error pages, you could check the following.

    If JavaScript is used to set or change image locations, it sometimes happens that an undefined makes its way into the URI.

    When that happens, the browser will happily try to load the image (no AJAX headers), but it will leave hints: it sets a particular Accept: header; instead of text/html, text/xml, ... it will use image/jpeg, image/png, ....

    Once such a header is confirmed, you have narrowed down the problem to images only. Finding the root cause will possibly take some time though :)

    Update

    To help debugging you could override $.fn.attr() and invoke the debugger when something is being assigned to undefined. Something like this:

    ​(function($, undefined) {
        var $attr = $.fn.attr;
    
        $.fn.attr = function(attributeName, value) {
            var v = attributeName === 'src' ? value : attributeName.src;
    
            if (v === 'undefined') {
                alert("Setting src to undefined");
            }
    
            return $attr(attributeName, value);
        }
    }(jQuery));
    
    0 讨论(0)
  • 2020-12-02 06:25

    I had a similar problem (but with /null 404 errors in the console) that @andrew-martinez's answer helped me to resolve.

    Turns out that I was using img tags with an empty src field:

    <img src="" alt="My image" data-src="/images/my-image.jpg">

    My idea was to prevent browser from loading the image at page load to manually load later by setting the src attribute from the data-src attribute with javascript (lazy loading). But when combined with iDangerous Swiper, that method caused the error.

    0 讨论(0)
提交回复
热议问题