Skip to main content
March 23, 2026Dan Rodney/6 min read

GreenSock: Preventing Flash of Unstyled Content on Load

Master GSAP animation loading and performance optimization

Core Learning Objectives

Network Simulation

Learn to use Chrome DevTools to simulate slow network conditions and identify loading issues in real-world scenarios.

FOUC Prevention

Implement visibility controls and event listeners to prevent flash of unstyled content during GSAP library loading.

Google Ads Validation

Understand Google's HTML5 ad requirements and use their validator to ensure compliance before submission.

Topics Covered in This JavaScript Tutorial:

Using Chrome's DevTools to Simulate Network Throttling, Eliminating Flash of Unstyled Content (FOUC) During Load, Validating Your Ad with Google's HTML5 Validator

Exercise Preview

performance hover over timeline

Exercise Overview

In this exercise, you'll tackle a common performance issue that plagues modern web animations: the dreaded flash of unstyled content (FOUC) that occurs before GSAP.js finishes loading. You'll master Chrome's DevTools performance profiling capabilities and learn the industry best practices for creating and validating Google Ads that pass platform requirements on the first submission.

Prerequisites Check

Ensure you have the GSAP-FOUC folder from the class files and a code editor that supports folder opening like Visual Studio Code. Disable ad blockers as they may prevent GSAP from loading properly.

Getting Started

  1. For this exercise we'll be working with the GSAP-FOUC folder located in Desktop > Class Files > JavaScript Class. Open that folder in your code editor if it allows you to (like Visual Studio Code does).
  2. In your code editor, open index.html from the GSAP-FOUC folder.
  3. Preview index.html in Chrome. (We'll be using its DevTools for performance analysis.)

    This is the animated banner ad you created in the previous exercise. While functional, it has performance issues that would be immediately flagged by any seasoned front-end developer or ad operations team.

    Important: If the animation fails to load, disable any ad blockers in your browser. Ad blockers can prevent GSAP libraries hosted on CDNs from loading properly—ironically creating the exact performance issues we're about to solve.

Project Setup Process

1

Open Project Folder

Navigate to Desktop > Class Files > JavaScript Class > GSAP-FOUC and open the folder in your code editor

2

Launch HTML File

Open index.html in your code editor and preview it in Chrome browser for DevTools access

3

Verify Animation

Confirm the animated banner ad works properly and disable any ad blockers if the animation fails to load

Using Chrome's DevTools to Simulate a Slow Network

Real users don't always enjoy the luxury of fiber-optic internet speeds. To build truly professional web experiences, you must test how your animations perform under realistic network conditions. Chrome's DevTools provides sophisticated network throttling capabilities that let you simulate everything from slow 3G to complete offline scenarios.

  1. Ctrl–click (Mac) or Right–click (Windows) anywhere on the page and choose Inspect from the context menu.
  2. In the DevTools panel, click on the Performance tab. If it's not visible, click the >> button to the right of the Elements tab and select Performance from the dropdown menu.
  3. Click the gear icon on the right to reveal the performance settings panel. We'll focus on the Network throttling options.

    performance show settings

  4. For Network throttling, select Slow 3G. This simulates conditions still common in many parts of the world and on mobile networks under poor signal conditions.
  5. At the top left of the DevTools panel, click the Record button to begin performance profiling.

    performance click record

    • Press Cmd–R (Mac) or Ctrl–R (Windows) to reload the page while recording.
    • Wait patiently for the banner animation to begin—throttled connections can take several seconds—then immediately click Stop to end the recording.
  6. Hover your cursor over the timeline to see frame-by-frame screenshots of what users actually experienced during the load process.

    performance hover over timeline

  7. While hovering over the timeline, move left and right to locate the page reload point. You'll notice the text appears immediately and remains visible for several seconds before suddenly disappearing and scaling back up.

    Here's what's happening behind the scenes: Before GSAP loads and initializes, browsers render HTML elements in their default state. Once GSAP finally downloads and parses your animation code, it immediately prepares elements for animation by setting their initial states (scaling down text, adjusting opacity, etc.). This preparation causes the visible "flash" as elements jump from their natural state to their animation-ready state.

    This flash of unstyled content (FOUC) is unprofessional and jarring for users. On slower connections—which represent a significant portion of global web traffic—this delay can last several seconds. Fortunately, there's a straightforward solution that every professional front-end developer should know.

Network Throttling Setup

1

Access DevTools

Right-click on the page and select Inspect, then navigate to the Performance tab

2

Configure Throttling

Click the gear icon to show settings and set Network throttling to Slow 3G

3

Record Performance

Click Record, reload the page with Cmd-R or Ctrl-R, then stop recording when animation begins

4

Analyze Timeline

Hover over the timeline to see screenshots and identify when text appears before disappearing and scaling up

Performance Issue Identified

On slow connections, users see unprepared text assets before GSAP loads and hides them for animation. This creates an unprofessional flash of unstyled content that needs to be addressed.

Preventing a Flash of Unstyled Content (FOUC) on Page Load

The industry-standard approach to eliminating FOUC involves hiding content until all critical resources have loaded, then revealing everything simultaneously as the animation begins. This creates a smooth, professional user experience regardless of connection speed.

  1. In your code editor, navigate to the css folder and open main.css.
  2. In the #banner rule, add visibility: hidden as shown below:

    #banner {
       visibility: hidden;
       overflow: hidden;

    Code Omitted To Save Space

    }
  3. Save the file and reload the page in Chrome.

    The banner should now be completely hidden, displaying only the gray background. This ensures users never see the unstyled content. Next, we'll programmatically reveal the banner once all resources have loaded using JavaScript event listeners.

  4. Event listeners execute functions when specific events occur. In index.html, wrap your entire animation code within a function:

    <script>
    function animate() {
       let tl = gsap.timeline( {repeat:3, repeatDelay:2} );

    Code Omitted To Save Space

    .from('#order-now', {duration:0.5, scale:0, opacity:0, ease:'back.out'})
    }
    </script>
  5. Below the function, add an event listener that triggers the animation only after the page and all its resources have completely loaded:

    }
    window.addEventListener('load', animate);
    </script>
  6. Finally, instruct GSAP to reveal the banner immediately before starting any animations:

    tl
    .set('#banner', {visibility:'visible'}).from('#panel1-text', {duration:0.5, scale:0.5, opacity:0, ease:'back.out'})
  7. Save your changes and reload the page in Chrome.

    • With network throttling still active, observe how the page now displays only the gray background during the loading process.
    • Once all resources finish loading, the red banner background appears instantly and the animation begins immediately—no flash, no jarring transitions.

    This professional approach ensures a consistent, polished user experience across all network conditions.

  8. In the Performance panel, reset the Network throttling to No throttling to restore normal speeds.
  9. Close the DevTools panel to return to normal browsing mode.

FOUC Prevention Implementation

1

Hide Initial Content

Add 'visibility: hidden' to the #banner CSS rule in main.css to hide content during loading

2

Wrap Animation in Function

Create an animate() function in index.html that contains the entire GSAP timeline animation code

3

Add Event Listener

Use window.addEventListener('load', animate) to trigger animation only after page fully loads

4

Reset Visibility

Add .set('#banner', {visibility:'visible'}) to the timeline before other animations to show content

Solution Verified

With throttling enabled, users now see only the gray background during loading, followed immediately by the banner appearance and smooth animation start once everything is ready.

For Your Reference: Checking Your Ad Using the Google Ads HTML5 Validator

Before submitting ads to major platforms like Google Ads, you must ensure they meet strict technical requirements. These guidelines exist to maintain platform performance and user experience standards. Failing to validate your ads beforehand often results in rejection and project delays.

Google HTML5 ads must comply with the following requirements as of 2026:

  • File size limit: Maximum 150 KB total (GSAP libraries and Google Fonts are excluded from this calculation).
  • Font restrictions: Custom fonts must be sourced exclusively from Google Fonts. No local font files or third-party font services are permitted.
  • File count limit: Maximum 40 files per ad package.
  • Size declaration: You must include a meta tag specifying the ad dimensions using Google's approved sizes:

    <meta name="ad.size" content="width=300, height=250">

    Note: This meta tag has been included in the project files as a reference example.

  • Click handling: Never hard-code destination URLs. Google's ad platform dynamically inserts click destinations through their clickTag system. Wrap your entire ad in a link element that references this clickTag variable. An implementation example is included in the project files.
  • Updated guidelines: Google continues to refine their HTML5 requirements. For the most current specifications, consult support.google.com/admanager/answer/7046799

Package all files into a compressed .zip folder for submission to Google. Before submitting, always validate your package using Google's official validator at h5validator.appspot.com/adwords/asset. This tool catches common issues that would otherwise result in rejection.

Common validation gotcha: Google Fonts automatically includes preconnect link tags in their generated code, but Google's ad validator flags these as violations. You must manually remove the following lines before validation:

<link rel="preconnect" href="https://fonts.googleapis.com"> 
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

Google HTML5 Ad Requirements

File Size Limit
150
Maximum Files
40

Google Ads Compliance Checklist

0/6
Validation Best Practice

Always run your compressed zip file through Google's H5 validator before submission to catch compliance issues early and avoid rejection delays.

Key Takeaways

1Chrome DevTools Performance tab with network throttling helps identify loading issues that affect user experience on slower connections
2Flash of Unstyled Content occurs when GSAP takes time to load, causing users to see unprepared assets before animation begins
3Setting visibility hidden on animated elements and using load event listeners prevents FOUC by hiding content until fully ready
4GSAP timeline.set() method should reset visibility to visible before starting animations to ensure proper display timing
5Google HTML5 ads have strict requirements including 150 KB file size limit and maximum 40 files, excluding GSAP and Google Fonts
6Google Fonts preconnect links must be removed from ad files to pass HTML5 validation despite being automatically included
7All ad files must be compressed into a zip file and validated using h5validator.appspot.com before submission to Google
8Proper meta tags for ad dimensions and clickTag link structure are mandatory for Google Ads campaign integration

RELATED ARTICLES