• Resolved robobalasko

    (@robobalasko)


    Hi,

    Our website uses WooCommerce 8.5.2 with Woodmart theme + WP Rocket for page cache. Ever since we upgraded from WC 8.4 to WC 8.5.2 we are experiencing an issue with wp.data being undefined for anonymous users.

    I have tested this issue on a brand new installation of WP with only WooCommerce and Woodmart theme being installed + WP Rocket. No other plugins and the issue is the same.

    It has already been discussed in this topic: https://www.ads-software.com/support/topic/js-errors-in-woocommerce-8-5-1/ Our issue is basically the same. Also, the process of resolving it is similar. WP Rocket offers an option to defer JS loading and to delay its execution. When I check these to option (which means that JS is not deferred and execution is not delayed until a user makes an action on the page, e.g. a scroll) everything works fine.

    However, I cannot keep this turned off because they slow the website and we get a 47 google page speed score instead of the stable 81 that we have kept for a long time.

    The problem is not present for logged in users. However, most of our customers place orders and use the website anonymously without creating an account.

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

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

  • The issue you’re experiencing with wp.data being undefined for anonymous users after updating WooCommerce and using WP Rocket for caching, combined with the Woodmart theme, is indicative of a JavaScript loading or execution timing issue. This can happen when scripts that rely on wp.data are executed before wp.data itself is fully loaded, especially when JS loading optimizations like deferring or delaying execution are applied.

    Given that disabling the defer and delay options in WP Rocket resolves the issue but adversely affects your site’s performance, here are some strategies to tackle the problem without sacrificing page speed:

    1. Selective Script Exclusion from Defer/Delay

    • Identify Critical Scripts: Determine which scripts are crucial for wp.data and ensure they are not deferred or delayed. You might need to manually exclude these specific scripts from WP Rocket’s optimization features.
    • WP Rocket Exclusion: In WP Rocket, you can exclude specific JavaScript files from being deferred or delayed. This is done under the File Optimization tab, where you can specify scripts by their relative paths.

    2. Async Loading with Dependency Management

    • Ensure Dependencies Are Met: If possible, modify how scripts are enqueued in WordPress to ensure that they explicitly declare wp.data as a dependency. This might require custom code or a child theme to adjust the script enqueue functions.

    3. Use of the rocket_delay_js_exclusions Filter

    • Custom Filter for Exclusions: WP Rocket allows you to exclude scripts from delay using the rocket_delay_js_exclusions filter. You can add a custom function to your theme’s functions.php file or a site-specific plugin to exclude scripts related to WooCommerce and wp.data.

    4. Optimize Loading with Inline Scripts

    • Inline Critical JS: For essential inline scripts that depend on wp.data, ensure they are placed in a way that they execute after wp.data is available. This might involve moving inline scripts to the footer or after the WP Rocket script that initializes deferred scripts.

    5. Contact Theme and Plugin Developers

    • Report the Issue: Since this issue persists with just WooCommerce, Woodmart theme, and WP Rocket activated, reaching out to the developers with detailed information might prompt them to investigate potential compatibility issues or offer a patch/update.

    6. Monitoring and Testing

    • Use Browser DevTools: Utilize your browser’s developer tools to monitor the loading order of scripts. This can help identify if critical scripts are loading too late due to deferring or delay optimizations.
    • Incremental Changes: Make one change at a time and test the site’s functionality and performance to pinpoint the most effective solution without compromising site speed.

    7. Alternative Performance Optimization

    • Reevaluate Caching and Optimization Settings: If specific exclusions don’t fully resolve the issue, consider adjusting other WP Rocket settings, like cache lifespan, file optimization levels, or using its Critical Path CSS generation feature to improve load times without affecting script execution.

    ?? hey @robobalasko

    Thanks for reaching out to Woo Support!

    the process of resolving it is similar. WP Rocket offers an option to defer JS loading and to delay its execution. When I check these to option (which means that JS is not deferred and execution is not delayed until a user makes an action on the page, e.g. a scroll) everything works fine.

    From what I gather, the reported issue’s culprit is with the caching plugin’s settings.

    Feel free to reach out to its support channel (linked here), as they would be in a better position to assist you.

    I trust that points you in the right direction, but if you have more questions, let us know.

    We’re happy to help.

    Thank you for chiming-in @isodos.

    Thread Starter robobalasko

    (@robobalasko)

    Hello @anastas10s,

    Thank you very much. The problem disappeared after updating to WC 8.6 today.

    Best regards,

    Thread Starter robobalasko

    (@robobalasko)

    I’m closing this thread as resolved.

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @robobalasko,

    That’s great to hear! Thanks for letting us know.

    Should you have further inquiries, kindly create a new topic here.

    Meanwhile, if it isn’t too much to ask for – would you mind leaving us a review here?

    It only takes a couple of minutes but helps us tremendously. It would mean so much to us and would go a really long way.

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘wp.data undefined in WooCommerce 8.5.2’ is closed to new replies.