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

Set Custom CSS IDs for Individual Divi Accordion Items

Assigning unique CSS IDs to specific Divi Accordion items allows for precise control over styling, targeting, and linking within your page content. This ability is particularly useful when you want to apply custom designs or create anchor links to particular accordion...

Enable Swipe Navigation in the Divi Gallery Lightbox

Enabling swipe navigation in the Divi Gallery module's lightbox allows users to seamlessly browse through gallery images by swiping left or right, creating a more interactive and mobile-friendly experience. This functionality can significantly improve user engagement...

Disable Slide-In Animation for Divi Gallery Grid Images

Control how images appear in your Divi Gallery module by toggling the slide-in animation effect for grid layouts. Disabling the slide-in animation allows gallery images to load instantly and appear statically, providing a faster and distraction-free browsing...

Control Image Count Display in Divi Gallery Lightbox

Displaying or hiding the image count in the Divi Gallery module’s lightbox can help customize the user experience, depending on whether you want to give visitors an indication of gallery progress or prefer a cleaner, distraction-free view. The ability to toggle this...

Hide Gallery Image Titles in the Divi Lightbox Overlay

Displaying image titles in the lightbox overlay of the Divi Gallery module can sometimes be distracting or unnecessary, depending on your website’s design and user experience goals. Hiding these titles creates a cleaner and more focused viewing experience for visitors...

Random Posts

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