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.

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.

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 *.

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

Latest From Divi Booster

How to Add the Post Status in Divi's Dynamic Content

Divi's Dynamic Content feature is great for enhancing your post/page templates with post-specific information. While Divi includes an option to show information such as the Post Created Date using Dynamic Content, there is no equivalent option for the Post Status....

Fix Divi Text Module "Regular" Font Weight Not Working

Are you encountering an issue where the font weights in Divi's Text Module don't seem to apply as expected? In particular, you might find that when you set the text module's body text font weight to "Regular", your font is actually assigned a weight of 500 instead of...

Make the Divi Gallery Module Swipeable

The Divi Gallery Module comes with a slider mode that lets you display images in a slider with clickable left/right arrows to scroll through the images. For mobile / touchscreen users, you can improve the user experience by allowing your user to swipe to navigate to...

How to Use Divi Dynamic Content in Woo Modules Product Selector

Divi's Dynamic Content is a powerful feature that lets you populate your Divi modules and theme builder templates with data pulled in various sources, such as custom fields. This allows for efficient organization and maintenance of your sites.Unfortunately, Divi's...

Random Divi Posts