Fix Divi Mobile Menu not working with LiteSpeed Cache

Written by Dan Mossop

If you're using the Divi theme in tandem with LiteSpeed Cache's Edge Side Includes (ESI) feature and experiencing issues, it might be due to a known interaction between the two. This post explains what to do about it.

Note: this post is a write up of the diagnosis of the issue carried out in this reddit post.

Update: LiteSpeed has now been updated (v6.0) with a fix for the nonce issue described in this post.

To fix a malfunctioning Divi mobile menu with LiteSpeed Cache due to nonce issues:

  1. Update to LiteSpeed Cache v6.0 for the fix.
  2. Alternatively, disable LiteSpeed's ESI feature.
  3. Clear the cache to remove old content.

Overview of LiteSpeed Cache's Edge Side Includes Feature

A "nonce" is a hash used within WordPress / Divi to protect URLs and forms against certain types of misuse. They're unique to each user and have a limited lifespan. When a page with a nonce is cached, behavior such as broken forms and security errors may occur. As such, pages with nonces usually have to be left uncached, which can affect their performance.

To address this, LiteSpeed Cache introduced an ESI solution to cache WordPress nonces and their associated pages fully. When implemented, this allows for individual caching of nonces separate from the rest of the page content.

When ESI is enabled, LiteSpeed automatically registers some of Divi's nonces for ESI processing, including:

  • et-pb-contact-form-submit
  • et_frontend_nonce
  • et_ab_log_nonce

Conflict between LiteSpeed Cache ESI and the Divi Theme

In theory, LiteSpeed's ESI features should therefore be compatible with Divi. However, there is currently (as at 25 Nov 2023) a known issue in the latest version of LiteSpeed Cache (v5.7.0.1) that results in an incorrect replacement of the et_frontend_nonce in the source code.

Specifically, the code containing the frontend nonce gets changed from something like this:

var et_pb_custom = {... ,"et_frontend_nonce":"cd3112a755","...};

To something like this:

var et_pb_custom = {... ,"et_frontend_nonce":"
<!-- Block cached by LiteSpeed Cache 5.7.0.1 on 2023-11-22 17:34:45 -->","...};

The newline before the comment seems to be breaking the declaration, leaving et_pb_custom undefined. This triggers some JavaScript errors in the page such as:

Uncaught SyntaxError: Invalid or unexpected token
And:
ReferenceError: et_pb_custom is not defined

These errors can block some of Divi's features from working. In particular, it seems to affect the mobile menu "hamburger" button, preventing the mobile menu from being opened.

Resolving the Issue

LiteSpeed has now been updated (v6.0) with a fix for the nonce issue, so upgrading to the latest version of LiteSpeed should resolve the issue.

A workaround, should you be unable to update or continue having issues is to disable the ESI feature for the time being. After disabling ESI, ensure caches are cleared to avoid serving outdated or broken content.

We may earn a commission when you visit links on our website.

Supercharge Your Posts with AI-Generated CTAs

Transform your WordPress site with WP Magic CTAs. Our AI-driven plugin creates customized, highly-targeted call-to-actions for each post, helping you increase engagement and conversions effortlessly. Perfect for promoting offers, growing your email list, and directing traffic where you need it most.

Latest Posts

Customize Lightbox Title Styling in the Divi Gallery Module

Adjust the appearance of the lightbox title that appears when visitors open images from a Divi Gallery to align with your brand and improve readability. Refining the title’s color, size, and weight enhances visual hierarchy, accessibility, and overall polish. In this...

Center the Lightbox Image Count in the Divi Gallery Module

Centering the image count in a gallery lightbox creates a cleaner, more balanced presentation and makes it easier for visitors to see where they are in the image set. This simple visual tweak can enhance readability, especially with larger images and longer captions,...

Style the Divi Gallery Module Lightbox Image Count

Tailor the appearance of the image counter in the Divi Gallery module lightbox to match your brand and improve readability. By customizing the counter’s color and typography, you ensure it displays clearly and suits your design. In this guide we show you how to style...

Customize the Lightbox Image Background Color in the Divi Gallery

Control the color that appears behind your images when users open in the gallery lightbox, including support for semi-transparent hues. This helps improve contrast for transparent images, align the experience with your brand palette, and create a more polished viewing...

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

0 Comments

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.