• Hi Guys,

    When loading my page the only error I have is the following:

    Uncaught TypeError: $ is not a function
    at autoptimize_7d81ce8….php:4369
    (anonymous) @ autoptimize_7d81ce8….php:4369

    The affected line is the following:

    
    ;$(function($){"use strict";function insertParam(key,value){key=encodeURI(key);value=encodeURI(value);var kvp=document.location.search.substr(1).split('&');var i=kvp.length;var x;while(i--){x=kvp[i].split('=');if(x[0]==key){x[1]=value;kvp[i]=x.join('=');break;}}

    I do not know what this error is, any solution?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Frank Goossens

    (@futtta)

    well, in wordpress one is not supposed to use $ just like that, but to use the no-conflict jQuery instead, cfr. https://developer.www.ads-software.com/reference/functions/wp_enqueue_script/#comment-1473

    so ideally you should find the culprit code and (have someone) fix that. else you might be able to work around it by excluding some JS from optimization, but can’t tell you which one from where I’m sitting I’m afraid … ??

    Thread Starter RebellionNT1

    (@rebellionnt1)

    I have detected that the file js/script.js of my theme, Has this code:

    $(function($) {
    
        "use strict";
    
        function insertParam(key, value) {
            key = encodeURI(key);
            value = encodeURI(value);
    
            var kvp = document.location.search.substr(1).split('&');
    
            var i = kvp.length;
            var x;
            while (i--) {
                x = kvp[i].split('=');
    
                if (x[0] == key) {
                    x[1] = value;
                    kvp[i] = x.join('=');
                    break;
                }
            }
    
            if (i < 0) {
                kvp[kvp.length] = [key, value].join('=');
            }
    
            //this will reload the page, it's likely better to store this until finished
            document.location.search = kvp.join('&');
        }

    How can I modify it so it does not show autoptimize errors?.

    Best Regards

    Plugin Author Frank Goossens

    (@futtta)

    As per the info in the link above, wrap the entire block in e.g.;

    (function( $ ) {
        // add your $-dependant javascript code here 
    })(jQuery);
    Thread Starter RebellionNT1

    (@rebellionnt1)

    I put it this way and it still gives the error: Is correct?

    $(function($) {
    
        "use strict";
    
        function insertParam(key, value) {
            key = encodeURI(key);
            value = encodeURI(value);
    
            var kvp = document.location.search.substr(1).split('&');
    
            var i = kvp.length;
            var x;
            while (i--) {
                x = kvp[i].split('=');
    
                if (x[0] == key) {
                    x[1] = value;
                    kvp[i] = x.join('=');
                    break;
                }
            }
    
            if (i < 0) {
                kvp[kvp.length] = [key, value].join('=');
            }
    
            //this will reload the page, it's likely better to store this until finished
            document.location.search = kvp.join('&');
        }(jQuery);

    Best regards

    Plugin Author Frank Goossens

    (@futtta)

    no, that’s no correct, try this instead;

    (function($) {
        $(function($) {
            "use strict";
    
            function insertParam(key, value) {
                key = encodeURI(key);
                value = encodeURI(value);
    
                var kvp = document.location.search.substr(1).split('&');
    
                var i = kvp.length;
                var x;
                while (i--) {
                    x = kvp[i].split('=');
    
                    if (x[0] == key) {
                        x[1] = value;
                        kvp[i] = x.join('=');
                        break;
                    }
                }
    
                if (i < 0) {
                    kvp[kvp.length] = [key, value].join('=');
                }
    
                //this will reload the page, it's likely better to store this until finished
                document.location.search = kvp.join('&');
            }
        }
    }(jQuery);
    Thread Starter RebellionNT1

    (@rebellionnt1)

    If I try with that code, the slider of my web does not work, any ideas?

    Best regards.

    Plugin Author Frank Goossens

    (@futtta)

    it’s very much possible that the error we’re discussing here is blocking the slider ??

    Thread Starter RebellionNT1

    (@rebellionnt1)

    As I can give you more information to try to solve the problem?, with the original code the slider works correctly, but with its correction fails.

    Best Regards

    Plugin Author Frank Goossens

    (@futtta)

    ah, I misunderstood ??

    In that case I would roll-back the change, no?

    Thread Starter RebellionNT1

    (@rebellionnt1)

    I have left the file as it originally came, because with your change the slider does not work for me.

    Best Regards.

    Plugin Author Frank Goossens

    (@futtta)

    that seems like a sensible thing to do. to fix the original error, i would get in touch with the theme-developer and ask him/ her to adapt it so it doesn’t depend on the pre-existance of $ any more.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Uncaught TypeError’ is closed to new replies.