Mosaic is officially live. Built over years and shaped by real projects, ready for you to start building.
Delayed script caused slow loading

Delayed script caused slow loading

Performance optimization tools often delay JavaScript execution, which gives better scores on speed tests, but they are actually slowing down the website's loading. This guide explains how Mosaic handles such cases, and what additional options you have.

Some performance optimization plugins and services modify how JavaScript files are loaded by applying defer or delay strategies. While this usually improves performance, it can delay the execution of critical scripts that are required for the page to render.

As a result, the page appears slowly until those scripts finally run.

What causes this?

This issue typically occurs when a third-party optimization tool delays JavaScript execution. Common examples include:

  • LiteSpeed Cache
  • WP Rocket
  • FlyingPress
  • Perfmatters
  • Autoptimize
  • NitroPack
  • Cloudflare Rocket Loader

These tools often delay or defer JavaScript to improve performance metrics, but in some cases they may also affect scripts that should run immediately.

How Mosaic handles this

Mosaic identifies critical JavaScript files that are required for proper and immediate rendering of the page.

To ensure correct behavior, Mosaic includes compatibility logic for several popular optimization plugins. It automatically excludes its critical scripts from deferred or delayed loading wherever possible.

This is typically done using plugin-specific attributes or filters, such as:

  • data-cfasync="false" (Cloudflare)
  • data-no-optimize="1" (Autoptimize, Cloudflare)
  • data-no-defer="1" (LiteSpeed, Perfmatters)
  • data-no-delay="1" (Flying Scripts, Perfmatters)
  • data-no-async="1" (Async JavaScript plugin)

Additionally, some plugins provide their own exclusion mechanisms (e.g. WP Rocket’s rocket_exclude_js filter), which Mosaic supports where applicable.

Cloudflare Rocket Loader

It is not possible to detect Cloudflare Rocket Loader automatically, so it requires manual configuration.

To ensure compatibility, you need to enable the following constant in your wp-config.php file:

Code
define('MOSAIC_CLOUDFLARE_ROCKET_LOADER', true);

This allows Mosaic to properly exclude its critical scripts from being delayed by Rocket Loader.

Recommendation

If you experience slow page rendering or delayed visibility:

  1. Check if any optimization plugin is delaying JavaScript execution.
  2. Make sure Mosaic scripts are excluded from defer/delay features.
  3. If using Cloudflare Rocket Loader, enable the constant above.

Proper configuration ensures that performance optimizations do not interfere with essential functionality.

Last updated: April 27, 2026

Still have more questions? Let us help!

Your cookie preferences

We use cookies to improve your experience, analyze traffic, and personalize content. By clicking "Accept all" you agree to storing them on your device. Read our privacy policy.