Starting with WordPress 6.3, the way we handle script loading in themes and plugins received a modern upgrade. In this post, we’ll explain the new 'strategy'
argument, how it complements or replaces 'in_footer'
, and how to use both properly for optimal performance.
WordPress 6.3 introduced a cleaner, more future-friendly approach for handling script loading behavior with the
'strategy'
argument.
What Changed in WordPress 6.3?
Prior to version 6.3, developers used the fifth parameter of wp_enqueue_script()
to specify whether the script should be loaded in the footer using 'in_footer' => true
.
While this still works, WordPress 6.3 added support for a more flexible and modern approach: the 'strategy'
parameter.
'in_footer'
(deprecated behavior): A boolean that defines if the script loads in the footer (true) or header (false).'strategy'
(new): A string that accepts either'defer'
or'async'
, providing more control over script loading behavior in modern browsers.
Correct Usage
Here’s how you should enqueue scripts today:
wp_register_script(
'my-script',
get_template_directory_uri() . '/js/my-script.js',
array(),
'1.0.0',
array(
'strategy' => 'defer'
)
);
wp_enqueue_script('my-script');
If you still want to control script placement explicitly:
wp_register_script(
'legacy-script',
get_template_directory_uri() . '/js/legacy.js',
array(),
'1.0.0',
array(
'in_footer' => true
)
);
wp_enqueue_script('legacy-script');
And yes, you can use both together:
wp_register_script(
'hybrid-script',
get_template_directory_uri() . '/js/hybrid.js',
array(),
'1.0.0',
array(
'in_footer' => true,
'strategy' => 'defer'
)
);
wp_enqueue_script('hybrid-script');
Using
'strategy' => 'defer'
can improve loading performance and reduce render-blocking issues caused by JavaScript files.
When to Use ‘defer’ or ‘async’
Choosing between ‘defer’ and ‘async’ depends on how your script behaves and whether it relies on other scripts or the DOM. Both attributes improve loading performance, but each has a specific use case.
- Defer: Executes script after HTML parsing is complete, in order. Best for scripts that rely on DOM being ready.
- Async: Executes script as soon as it’s downloaded, possibly out of order. Use when script does not depend on other scripts or DOM.
Advantages of the New Strategy
Adopting the new 'strategy'
parameter helps align your codebase with modern performance practices:
- Reduces render-blocking time
- Improves Core Web Vitals and page speed scores
- Provides clearer intention (vs ambiguous footer placement)
- Supports better caching and script prioritization
Best Practices
To maximize performance and avoid script-related conflicts, it’s important to understand how different loading strategies interact with your site’s structure and dependencies.
Choosing the right strategy not only improves page speed and SEO metrics but also ensures that your scripts run at the correct time without breaking functionality.
- Use
'strategy' => 'defer'
for non-critical scripts - Use
'strategy' => 'async'
only if the script is self-contained - Avoid mixing
async
with dependent scripts - Prefer
wp_register_script
+wp_enqueue_script
for cleaner code
While
'in_footer'
still works, migrating to'strategy'
prepares your theme or plugin for long-term compatibility and performance gains.