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

前端 未结 8 2169

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));
    

提交回复
热议问题