• Resolved jeroenm77

    (@jeroenm77)


    Hi,

    I have an issue, probably started after updating to 5.5.1 or 5.5.0. Some part of our site stopped working, and an error is shown in the chrome inspector:
    Uncaught reference error: wp not defined

    It points me to: wp.i18n.setLocaleData( localeData, domain );

    When I disable Autoptimze the error is gone, but the site still doesnt function 100% (reserving a car from a certain screen (see link) results in reloading the same screen instead of going to the next step). If you try to reserve a car from the mainpage it does work without any problem.

    However its very possible that these are two seperate errors I hope fixing one could help me fix the other.

    I have tried installing the jQuery migrate helper, but doesnt seem to have any (desired) effect.

    Do you have any ideas on how to approach this Frank?

    Thanks!

    • This topic was modified 6 years, 2 months ago by jeroenm77.

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

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

    (@optimizingmatters)

    Hmm, based on the error maybe start by adding wp-includes/js to the comma-separated JS optimization exclusion list?

    Thread Starter jeroenm77

    (@jeroenm77)

    That didnt help. My current exclusion list is this:

    wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js

    Thread Starter jeroenm77

    (@jeroenm77)

    I have managed to fix one of the issues. Probably the code used some sort of side effect or something, that with 5.5.1 didnt work anymore. Rewrote some of the code and now the reservation process works.

    The error: “Uncaught reference error: wp not defined” remains unchanged tho

    Sorry for all the editing. Your reply got me thinking again, and I realised you helped me out with another issue a while back. For that issue we needed a code snippet that disables autoptimize for my reservation process. If I disable that code, the error disappears. The snippet contains this code:

    add_action('plugins_loaded','ao_defer_inline_init');
    
    function ao_defer_inline_init() {
    	if ( get_option('autoptimize_js_include_inline') != 'on' ) {
    		add_filter('autoptimize_html_after_minify','ao_defer_inline_jquery',10,1);
    	}
    }
    
    function ao_defer_inline_jquery( $in ) {
      if ( preg_match_all( '#<script.*>(.*)</script>#Usmi', $in, $matches, PREG_SET_ORDER ) ) {
        foreach( $matches as $match ) {
          if ( $match[1] !== '' && ( strpos( $match[1], 'jQuery' ) !== false || strpos( $match[1], '$' ) !== false ) ) {
            // inline js that requires jquery, wrap deferring JS around it to defer it. 
            $new_match = 'var aoDeferInlineJQuery=function(){'.$match[1].'}; if (document.readyState === "loading") {document.addEventListener("DOMContentLoaded", aoDeferInlineJQuery);} else {aoDeferInlineJQuery();}';
            $in = str_replace( $match[1], $new_match, $in );
          } else if ( $match[1] === '' && strpos( $match[0], 'src=' ) !== false && strpos( $match[0], 'defer' ) === false ) {
            // linked non-aggregated JS, defer it.
            $new_match = str_replace( '<script ', '<script defer ', $match[0] );
            $in = str_replace( $match[0], $new_match, $in );
          }
        }
      }
      return $in;
    }
    • This reply was modified 6 years, 2 months ago by jeroenm77.
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Had a quick look, I’m not seeing wp not defined any more though?

    Thread Starter jeroenm77

    (@jeroenm77)

    I had the code snippet disabled to test it, and thus is dissappeared, I’ll enable the snippet again now

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    hmm, you could try changing

    if ( $match[1] !== '' && ( strpos( $match[1], 'jQuery' ) !== false || strpos( $match[1], '$' ) !== false ) ) {

    into
    if ( $match[1] !== '' && ( strpos( $match[1], 'jQuery' ) !== false || strpos( $match[1], '$' ) !== false ) || strpos( $match[1], 'wp.' ) !== false ) ) {

    Thread Starter jeroenm77

    (@jeroenm77)

    Yes, that did the trick! Thanks so much again πŸ™‚

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    graag gedaan Jeroen πŸ™‚

Viewing 8 replies - 1 through 8 (of 8 total)

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