• Resolved playalistic_p

    (@playalistic_p)


    Hi there,
    I installed WooCommerce for the first time and right now are in the progress of creating/modifying the necessary pages for the users.

    When i drop the “All products” block on the shop page in Gutenberg editor, my 3 test-products are shown fine.

    But when i visit the actual page, i get the following error:
    Uncaught ReferenceError: wp is not defined at bortec-tuning.de/:2:843

    At the above location there is this 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>

    I have Autoptimize and Async JavaScript installed, but this particular snippet is the only one on that page that has no defer attribute attached and is not minimized. Why is this omitted by both plugins?

    Now when i deactivate Autoptimize AND Async JavaScript, everything works fine. As soon as one of the two plugins is activated it does not work again (with other errors).

    Thank you in advance!

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

Viewing 13 replies - 16 through 28 (of 28 total)
  • Thread Starter playalistic_p

    (@playalistic_p)

    Both plugins where installed like 2 years ago to boost performance, user experience and to get a better scoring in PageSpeed Insights. Score of the mobile test is still very poor btw (around 50).

    I interpret your question as if AsyncJS could not further improve performance if Autoptimize already aggregated all the JS code?

    well, AO is now configured not to aggregate/ defer _all_ JS, but it might be impossible to defer (async) all of that given the problems you were facing?

    Thread Starter playalistic_p

    (@playalistic_p)

    It is possible by simply removing an implode(“\n”) in the script-loader.php as i have already written in an earlier post.

    I think this is a bug in Autoptimize, somehow this particular newline renders AO to skip this single snippet (not minified, not aggregated, not deferred), which in turn breaks the page as all the other code is deferred correctly.

    I rather go with a modified script-loader.php instead of deactivating AsyncJS.

    what in the HTML output is the difference with and without the implode? is the JS output still correct with the implode removed?

    Thread Starter playalistic_p

    (@playalistic_p)

    OK, i must apologize, i thought by removing the implode that the output would be in a single line rather than with line breaks.

    Should have checked the source code, the output without implode is simply “Array”. No wonder why it worked then.

    Found out that instead the WooCommerce dashboard was not working anymore. So reverted back to the original file.

    So right now it only works when AsyncJS is deactivated and AO is not aggregating inline JS and wp-includes/js is excluded.

    OK, good to know! Now concerning AsyncJS; what could be happening is that it -mistakingly- is adding async (or defer) flags in the inline JS with the apiFetch code, can you check if that indeed is happening? maybe copy-paste the entire HTML source to a pastebin paste (or github gist) so I can have a look too?

    Thread Starter playalistic_p

    (@playalistic_p)

    I guess with AsyncJS enabled again and without any exclusions? You want the HTML source code of the page that produces the uncaught reference error?

    the HTML source code with wp-includes/js excluded please (ready to clsse shop for the day, so I’ll follow up somewhere over the weekend) 🙂

    Mirko P.

    (@rainfallnixfig)

    Hi @playalistic_p,

    This forum is specific for WooCommerce core issues so you might want to follow up with Autoptimize devs on their support forum.

    If you have any WooCommerce core questions feel free to create a new topic.

    Thank you for your understanding.

    Thread Starter playalistic_p

    (@playalistic_p)

    @rainfallnixfig
    Can i or someone else move this topic to Autoptimize?

    @optimizingmatters
    Here you go: https://gist.github.com/playalisticp/da700f4eece630e99a18031efa9ee56b

    feel free to start a new support topic in the AsyncJS forum (as things are OK with AO now) playalistic_p, I’ll take it up there tomorrow 🙂

    frank

    Thread Starter playalistic_p

    (@playalistic_p)

    Perfect.

    Feel free to create another topic here if you have any other questions related to WooCommerce core.

Viewing 13 replies - 16 through 28 (of 28 total)

The topic ‘Uncaught ReferenceError: wp is not defined’ is closed to new replies.