• Hi, Install the plugin on my test site, with the following configuration:

    Optimize HTML Code? – enable
    Keep HTML comments? – enable

    Optimize JavaScript Code? – enable
    Force JavaScript in <head>? – disable
    Also aggregate inline JS? – disable
    Exclude scripts from Autoptimize – seal.js,js/jquery/jquery.js,/wp-includes/js/jquery/jquery.js
    Add try-catch wrapping? -disable

    The site does not load and I have this error:

    Uncaught TypeError: $ is not a function
    at HTMLDocument.<anonymous> (autoptimize_2e4c88e0c733ed70658922a1e1392cfd.js:21)
    at j (autoptimize_2e4c88e0c733ed70658922a1e1392cfd.js:3)
    at Object.fireWith [as resolveWith] (autoptimize_2e4c88e0c733ed70658922a1e1392cfd.js:3)
    at Function.ready (autoptimize_2e4c88e0c733ed70658922a1e1392cfd.js:3)
    at HTMLDocument.J (autoptimize_2e4c88e0c733ed70658922a1e1392cfd.js:3)
    autoptimize_2e4c88e0c733ed70658922a1e1392cfd.js:21 Uncaught TypeError: $ is not a function
    at autoptimize_2e4c88e0c733ed70658922a1e1392cfd.js:21
    at dispatch (autoptimize_2e4c88e0c733ed70658922a1e1392cfd.js:4)
    at r.handle (autoptimize_2e4c88e0c733ed70658922a1e1392cfd.js:4)

    Can you help me please?

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

    (@futtta)

    $ is not a function is a jquery-related error which is not uncommon on wordpress, which is why most plugins use jQuery instead of $ … if you can share your URL I’ll see what I can find out.

    Thread Starter dexter_ade

    (@dexter_ade)

    Hi Frank, this url: https://trucksandparts.staging.wpengine.com/ thank you for you help.

    Plugin Author Frank Goossens

    (@futtta)

    Well, the errors seem to come from JS that originates from wp-content/themes/trucksparts/js/functions.js, which seems (part of) a custom build theme and that script does not take the WordPress way of doing jQuery (i.e. the fact it loads jQuery in compatibility mode) into account.

    As it’s custom built, I would advice you -to ask the developers- to either change all occurences of $ with jQuery in that file or to apply one of the workarounds discussed in this or this article.

    hope this helps,
    frank

    Thread Starter dexter_ade

    (@dexter_ade)

    Hi Frank, thank you for you help, I made the changes to the file wp-content/themes/trucksparts/js/functions.js and now show this error:

    Uncaught TypeError: $ is not a function
    at HTMLDocument.<anonymous> (autoptimize_90cb36facc0b8b701feda0928c9b3312.js:366)
    at j (autoptimize_90cb36facc0b8b701feda0928c9b3312.js:3)
    at Object.fireWith [as resolveWith] (autoptimize_90cb36facc0b8b701feda0928c9b3312.js:3)
    at Function.ready (autoptimize_90cb36facc0b8b701feda0928c9b3312.js:3)
    at HTMLDocument.J (autoptimize_90cb36facc0b8b701feda0928c9b3312.js:3)

    Try searching for the autoptimize.js file to replace $ with jQuey but I did not find it, can you help whith this please.

    • This reply was modified 7 years, 10 months ago by dexter_ade.
    Plugin Author Frank Goossens

    (@futtta)

    well, I see this block of inline JS on the unoptimized HP:

    
    $(document).ready(function(){
        if($("select#select_1").val()=="Garbage Trucks"){
                $("select#select_2").html(refusetrucks);
            }
    	if($("select#select_1").val()=="Concrete Mixer Trucks"){
                $("select#select_2").html(concretetrucks);
            }
    	if($("select#select_1").val()=="All Other Trucks"){
                $("select#select_2").html(othertrucks);
            }
    	if($("select#select_1").val()=="Trailers"){
                $("select#select_2").html(trailers);
            }
        if($("select#select_1").val()=="Grapple Trucks"){
                $("select#select_2").html(grapple);
            }		
    		
    	//force display of updated selection
    	$("select#select_2").change();
    	$("select#select_1").on('change',function(){
            if($(this).val()=="Garbage Trucks"){
                $("select#select_2").html(refusetrucks);
            }else if($(this).val()=="Concrete Mixer Trucks"){
                $("select#select_2").html(concretetrucks);
            }else if($(this).val()=="All Other Trucks"){
                $("select#select_2").html(othertrucks);
            }else if($(this).val()=="Trailers"){
                $("select#select_2").html(trailers);
            }else if($(this).val()=="Grapple Trucks"){
                $("select#select_2").html(grapple);
            }
        });
    		
    });

    so at least that one, but maybe more?

    Thread Starter dexter_ade

    (@dexter_ade)

    Frank Thank you, I will continue to review and inform you as I was.

    Thread Starter dexter_ade

    (@dexter_ade)

    Hello Frank, Happy start of week, I already fix the problems of java script and I have no errors in the log, but now when I want to do the speed test in this url shows me an error:
    https://developers.google.com/speed/pagespeed/insights/?url=http%3A%2F%2Ftrucksandparts.staging.wpengine.com%2F&tab=desktop

    However when I disable the “Optimize JavaScript Code?” The page speed does not show any errors, what can be the problem?

    Plugin Author Frank Goossens

    (@futtta)

    Seems like a timeout @dexter_ade, although the page does load in a browser so it could be a fluke, but it is pretty slow in the browser to.

    The main reason is probably that you’re aggregating inline JS. As inline often contains changing variables, it busts the cache leading to a longer load-time and to fast growing cache-sizes.

    Other tips & tricks for similar situations;
    * make sure any of your own JS-files are pre-minified and that the filename end in .min.js or -min.js
    * optionally switch to the legacy minifiers (see FAQ for info on how to do that)
    * optionally exlude one of more JS-files (that don’t end in .min.js or -min.js) from optimization to lighten the minification-load

    hope this helps,
    frank

    Thread Starter dexter_ade

    (@dexter_ade)

    Thanks Frank for your response and your support, I will continue to debug. I hope to solve all those problems.

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