Stop Flash of Ugly Site While Divi Loads

Sep 21, 2020

Disclaimer: This site is a labour of love, but love doesn’t buy me matcha lattes. Affiliate commissions for awesome internet tools, on the other hand, totally buys me matcha lattes. This post probably contains some affiliate links. Read my affiliate disclaimer here.

Ever notice how there’s a flash of your ugly unstyled site before Divi loads?

Or perhaps elements that are disabled on desktop show up for a flash and then they disappear when Divi finally loads?

You may be thinking — like most designers — that this is just part of Divi; that it’s unavoidable unless you have a dedicated server.

But, it’s actually easy to fix with just 15 lines of code in the Header. And, full transparency, I figured this out from an old Stack Overflow forum thread from 10 years ago. 🙂

Step 1: Copy this code to your clipboard.

<style type="text/css">
        .fouc-fix { display:none; }
    </style>
<script type="text/javascript">
        try {
            var elm=document.getElementsByTagName("html")[0];
            var old=elm.class || "";
            elm.class=old+" fouc-fix";
            document.addEventListener("DOMContentLoaded",function(event) {
                elm.class=old;
                });
            }
        catch(thr) {
            }
</script>

Step 2: Paste in Theme Options

Open up Theme Options, and then go to Integration.

Paste the code into the first block where it says, “add code to the <head> of your blog.”

Save your changes.

Flush your cache, and then reload your site in Incognito Mode to ensure it worked.

Designerless: Divi Header Code

Hope this helps! Let me know in the comments.

0 Comments

Leave a Reply