• playalistic_p

    (@playalistic_p)


    Continuation of this topic from the WooCommerce forum: https://wordpress.org/support/topic/uncaught-referenceerror-wp-is-not-defined-6

    TLDR:
    Thought it was a WooCommerce issue, turned out that it’s most probably related to AsyncJS. When enabled i get:

    Uncaught ReferenceError: wp is not defined at bortec-tuning.de/:2:843

    In Line 843 there is this WooCommerce snippet:

    <script type='text/javascript' id='wp-api-fetch-js-after'>wp.apiFetch.use(wp.apiFetch.createRootURLMiddleware( "https://bortec-tuning.de/wp-json/" ) );
    wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "9f1078e68b" );
    wp.apiFetch.use( wp.apiFetch.nonceMiddleware );
    wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );
    wp.apiFetch.nonceEndpoint = "https://bortec-tuning.de/wp-admin/admin-ajax.php?action=rest-nonce";</script>

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    Can you toggle the “autoptimize integration” option in AsyncJS and retest playalistic_p ?

    Thread Starter playalistic_p

    (@playalistic_p)

    The option made no difference, did not work checked or unchecked as soon as AsyncJS was enabled.

    But since you suggested to keep “Aggregate inline JS” off and this did the trick with AO, i thought to give it a try and exclude wp-includes/js in AsyncJS too.

    Now this configuration works:

    Ao ON
    Aggregate JS ON
    Aggregate inline JS OFF
    Exclude wp-includes/js

    AsyncJS ON
    Method Defer
    jQuery Defer
    Exclude wp-includes/js

    Have you noticed that i posted the sourcecode here?
    https://gist.github.com/playalisticp/da700f4eece630e99a18031efa9ee56b

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Now this configuration works:

    Ao ON
    Aggregate JS ON
    Aggregate inline JS OFF
    Exclude wp-includes/js

    AsyncJS ON
    Method Defer
    jQuery Defer
    Exclude wp-includes/js

    great, but be careful with deferring jQuery, it is likely to occasionally break things even if things seem to work for you. the safer approach is not to defer/ async jQuery in this case.

    Thread Starter playalistic_p

    (@playalistic_p)

    Thank you, but what is now about the Uncaught ReferenceError? Are we closing the case because it is working now?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    ah, you’re still seeing an error despite the exclusion in both AO & AsyncJS??

    Thread Starter playalistic_p

    (@playalistic_p)

    No no, it is fixed with above configuration. But I mean, this feels like a workaround to exclude whole directories from optimization and turn off inline aggregation. Isn’t this a bug worth fixing? I’m a developer too, and such things trigger me to investigate and fix it.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Afraid some WordPress (Gutenberg) blocks add a lot of both inline and linked JavaScript playalistic_p and the inline JS depends on/ expects the linked JS to be there, so when deciding to use such blocks that are JS-heavy on the frontend, you will have to exclude a lot of WordPress core JS. You could make the exclusion more specific, but it’ll take trial and error to identify those.

    The alternative (apart from not using JS-heavy frontend blocks) would be not to use AsyncJS but only Autoptimize in the “don’t aggregate but defer” + “also defer inline JS” setup, but you tried that already and that did not work for you if I remember correctly?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Uncaught ReferenceError: wp is not defined’ is closed to new replies.