Support » Plugin: Autoptimize » Uncaught ReferenceError: wp is not defined

  • Resolved dasigna

    (@dasigna)


    hi there,

    … sorry, but have to ask.

    i am getting this error on every page with AO on.
    tried a myriad of options but still completely unable to track it down. depending on AO settings there are a lot more of this errors alike – up to 16 or 19 …

    so this state gives me already the best result but the one remains, no matter what.

    there are no errors with AO off.
    but then theres a ton of WP scripts inline which makes me wonder anyway.

    toolset already was a nightmare to get to work with AO… but everything works fine so far in terms of functionality on frontend.

    any quick look and a bit of help highly appreciated.
    thanks in advance.

    EDIT:
    had to disable ‘aggregate inline js’ due to toolset (delayed response) again, along with ‘minify excluded js and css.
    functions alright, but now 16 (!) console errors again.
    source code looks crazy.
    excluded js scripts: seal.js, js/jquery/jquery.js, js/jquery/jquery.min.js, views-frontend.js, toolset-common-es-frontend.js

    there seems to be something basic going comletely wrong – remember: no errors without AO.
    and… only site so far with this.
    curious about your verdict …

    EDIT TWO:
    o.k. alarm from red to orange :/
    adding wp-includes/js to exclusion solves the errors… but then theres all this nasty WPcode within source again. never seen this before in that way.
    something changed lately somewhere?

    anyway still hoping for clearance ๐Ÿ™‚ thanks

    • This topic was modified 2 months, 1 week ago by dasigna.
    • This topic was modified 2 months, 1 week ago by dasigna. Reason: typo
    • This topic was modified 2 months, 1 week ago by dasigna.
    • This topic was modified 2 months, 1 week ago by dasigna.

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

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

    (@optimizingmatters)

    Indeed, wp-includes/js needs to be excluded due to a major change in CF7’s frontend behavior .. :-/

    Thread Starter dasigna

    (@dasigna)

    …!?

    so you are saying this error is all due to CF7??? no CF7 – no headache?
    strange – had already disbled it with no effect…

    anyway – can’t leave this as it is! 77 requests in comparison to 22 without ‘wpincludes’. thats crazy!

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    will do some more tests tomorrow (21h09 here, have to call it a day) but that is my understanding yes ..

    Thread Starter dasigna

    (@dasigna)

    … same time here – so time to ditch off work for now, really ๐Ÿ™‚

    tomorrows another day. ill leave it as it is meanwhile and also will see again what the new day might bring.

    wait for your response, thanks so far.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    OK, tested CF7 + AO on a blank (localhost) site and the good news is that that works with the default AO settings (so with wp-includes/js/dist excluded but wp-includes/js NOT excluded). That seems to imply that in your case there is another 3rd party (likely plugin) involved in things breaking. Did you install/ update other plugins or did you recently started adding blocks (which can be JS-heavy) on the frontend ?

    Thread Starter dasigna

    (@dasigna)

    … back on the hunting track too here.

    meanwhile tested on staging and have to confirm it has nothing to do with CF7 obviously.
    regarding some blocks thing too as the culprit that throws a lot of primarily backend js … and gives tons of errors with AO or only one, depending on settings.
    and yes, completely rebuildt the page with block editor lately, using generateblocks and toolset.

    lately back to practically activating everything in AO including ‘aggregate inline js’, ‘add try catch block’ and ‘minify excluded css and js’ which gives me one last (mentioned) error. (not including inline js throws up to 16)

    excluded scripts: seal.js, js/jquery/jquery.js, js/jquery/jquery.min.js, views-frontend.js, toolset-common-es-frontend.js

    error from console (detected at line:1):

    1 ... || document.write( '<script src="https://xxx/wp-includes/js/dist/vendor/wp-polyfill-element-closest.min.js?ver=STAGING-2.0.2"></scr' + 'ipt>' );</script> <script id='wp-api-fetch-js-after'>wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "https://xxx/wp-json/" ) );
    2 wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "9417a9fcb2" );
    3 wp.apiFetch.use( wp.apiFetch.nonceMiddleware );
    4 wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );
    5 wp.apiFetch.nonceEndpoint = "https://xxx/wp-admin/admin-ajax.php?action=rest-nonce";</script>

    didnt find the bad guy yet … but anyway wondering what all this js that is visible without AO has to do within source code. youre able to see it in provided url.

    still hunting … but running out of ideas.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    well, inline JS containing document.write is auto-excluded from being optimized (as document.write doesn’t work when not in the HTML). the code is part of the wp-polyfill in WordPress core and is also there on my CF7+AO testsite (where “also aggregate inline JS” is off).

    my pov: be careful when doing everything with blocks, it can (and will, as you noticed) require quite a bit of JS being downloaded, parsed and executes, so it _will_ always have a performance impact.

    Thread Starter dasigna

    (@dasigna)

    … so that much to the great new block editor … ;/

    anyway: there are two plugins that seem to be involved when the error occurs.
    – CF7
    Image Comparison

    with both (or only one) active the errors occur – without theres neighter errors nor inline injection of wp js (edit: o.k. partly, but much less). regardless whether AO is advised to also aggregate inline js or not…

    so far at least. have to check it on live site again.

    • This reply was modified 2 months, 1 week ago by dasigna.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    so you have the error even if only using CF7+AO?

    Thread Starter dasigna

    (@dasigna)

    so you have the error even if only using CF7+AO?

    yep.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    and if you -briefly- switch theme?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    ah, I see you don’t have wp-includes/js/dist in your JS exclusion list, which is excluded by default, I assume (hope) things are not broken with that exclusion active?

    Thread Starter dasigna

    (@dasigna)

    and if you -briefly- switch theme?

    honestly didnt do so. its GeneratePress theme – in none of the numerous cases with errors during the last 5+ years this was the culprit. so did not test this, except from deactivating the pro version.
    wont expect any difference if doing so ๐Ÿ™‚

    ah, I see you donโ€™t have wp-includes/js/dist in your JS exclusion list, which is excluded by default, I assume (hope) things are not broken with that exclusion active?

    nothing broken. everythings fine.
    in contrary things get worse if doing so with CF7 installed …

    • This reply was modified 2 months, 1 week ago by dasigna.
    • This reply was modified 2 months, 1 week ago by dasigna.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    so AO+CF7 with js/dist excluded (and “include inline JS” off) still gives errors for you?

    Thread Starter dasigna

    (@dasigna)

    so AO+CF7 with js/dist excluded (and โ€œinclude inline JSโ€ off) still gives errors for you?

    no. but it gives still a too big amount of requests and lots of nasty inline js in source ๐Ÿ™‚

    so goodbye to CF7. no headaches then!

Viewing 15 replies - 1 through 15 (of 18 total)
  • You must be logged in to reply to this topic.