Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchOn WordPress 6.3 and later, defer an enqueued script by passing 'strategy' => 'defer' in the $args array of wp_enqueue_script(). Keep 'in_footer' => true when appropriate, and make sure the script’s dependency chain is compatible. If a script is already registered, use wp_script_add_data( $handle, 'strategy', 'defer' ). These APIs add the strategy without a filter hack; older WordPress versions simply ignore the strategy metadata.
Antihost offers managed WordPress hosting with free migration, one-click staging and a 14-day free trial.
How to defer javascript wordpress: what “defer” changes
A normal JavaScript file encountered in the document can block HTML parsing while the browser fetches and executes it. A deferred external script can be fetched while parsing continues and is evaluated after the document has been parsed. That can remove a render-blocking script from the critical path, but it also changes when the code runs.
As an Amazon Associate I earn from qualifying purchases.
Deferral is therefore an execution-order decision, not just a performance switch. Code that expects the DOM to be available generally fits deferred execution. Code that must run immediately, or inline code that expects a library to have loaded earlier, may fail when moved to the deferred phase.
WordPress added first-class support for both defer and async strategies in version 6.3. The native Scripts API is the preferred approach on current WordPress installations.
#1 Best Overall
WordPress defer javascript with wp_enqueue_script()
For a theme or plugin you control, set the strategy when enqueuing the file. The sixth argument is an array of options; use the existing footer option together with the strategy:
add_action( 'wp_enqueue_scripts', function () {
wp_enqueue_script(
'my-app',
get_stylesheet_directory_uri() . '/js/app.js',
array(),
'1.0.0',
array(
'in_footer' => true,
'strategy' => 'defer',
)
);
} );
What each argument does
- Handle:
my-appis the identifier WordPress uses for the script. - Source: the URL points to the JavaScript file in the active theme.
- Dependencies: the empty array means this example declares none. Add registered handles here when the file requires them.
- Version:
1.0.0is used for the script URL’s version value; replace it when your file changes. - Loading options:
in_footer => truerequests footer output, whilestrategy => 'defer'requests the deferred attribute.
Use the same pattern in a plugin, replacing the theme URL function with the plugin’s own asset URL. The important part is that the strategy is in the options array passed to wp_enqueue_script(), not appended manually to the URL.
wp_script_add_data defer: applying a strategy after registration
Sometimes a script is registered in one place and enqueued or modified later. In that case, add the strategy metadata to the existing handle:
add_action( 'wp_enqueue_scripts', function () {
wp_register_script(
'my-app',
get_stylesheet_directory_uri() . '/js/app.js',
array(),
'1.0.0',
true
);
wp_enqueue_script( 'my-app' );
wp_script_add_data( 'my-app', 'strategy', 'defer' );
} );
The final true in wp_register_script() requests footer placement. The subsequent wp_script_add_data() call adds the deferred strategy to the already-registered handle.
When this pattern is useful
- A plugin or theme registers the handle before another callback knows whether it should be deferred.
- You need to set the strategy after registration rather than changing the original enqueue call.
- You want one callback to register, enqueue, and annotate a controlled script explicitly.
WordPress 6.3 and later understand this metadata. Older WordPress versions ignore it without throwing an error, so those sites continue loading the script without a defer attribute. If deferral is a requirement on an older installation, upgrading WordPress is the predictable way to obtain the native API; otherwise, test any separate optimization mechanism carefully.
Choosing between the two native methods
| Method | WordPress support | Best use | Important limitation |
|---|---|---|---|
wp_enqueue_script( ..., array( 'strategy' => 'defer' ) ) |
WordPress 6.3+ | You own the enqueue call and can set loading options at registration time. | Requires the 6.3+ options-array API. |
wp_script_add_data( $handle, 'strategy', 'defer' ) |
Understood by WordPress 6.3+; ignored by older versions | The handle is already registered or the strategy must be applied later. | Older versions receive no defer behavior and no error. |
Both methods express the same strategy to WordPress. Select the one that matches where the script is registered and how much control you have over its dependency chain.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Footer placement, modules, and the strategy caveat
WordPress’s developer reference includes a placement requirement: a script with a strategy must either be printed in the footer (in_footer => true) or use a deferred strategy. This allows script-module import maps to be printed before the associated script is evaluated.
Using in_footer => true in the examples satisfies that requirement and also avoids putting the tag in the document head when footer output is suitable. Do not assume that moving every script to the footer is harmless: a script required by head-level markup, an early inline block, or another library may need a different loading plan. Treat placement and strategy as related settings, then verify the generated HTML.
Dependency rules you must preserve
WordPress tracks dependencies by handle, but it cannot make an unsafe execution graph safe merely by adding one attribute. For a deferred script, the dependency rules are:
- Its dependencies must use
deferor remain blocking. - Its dependents must also use
defer. - The resulting chain must preserve the order in which dependent code expects to run.
A safe chain
Suppose app depends on vendor. If both are deferred, the browser can evaluate them in dependency order after parsing. If vendor remains blocking, app can still depend on it because the dependency is available before the deferred code executes.
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #3
An unsafe chain
If app is deferred but a dependent script expects app to have executed immediately, that dependent code can run at the wrong time. Likewise, changing a shared library to deferred can break another handle that still assumes the library is available during parsing. Before changing a third-party handle, inspect which scripts depend on it rather than considering only the file you want to optimize.
Should you defer jQuery or third-party libraries?
Keep jQuery and similar foundational libraries out of a deferred set unless you have tested every consumer. Deferred scripts run after the document is parsed, so inline code that expects the library to exist earlier can fail. The same warning applies to third-party handles used by several plugins: one plugin may work while another loses its expected initialization order.
Start with scripts you own
- Identify a theme-owned or plugin-owned bundle whose code waits for the DOM and has a clear dependency list.
- Apply
'strategy' => 'defer'at enqueue time, or add the strategy to its registered handle. - Test pages that use the bundle, including pages with forms, menus, media players, checkout-like interactions, and logged-in admin bars if your site exposes them.
- Only then consider a shared library or a third-party handle, and change one dependency group at a time.
Defer versus async in WordPress
WordPress 6.3 supports both 'defer' and 'async' as script strategies. They are not interchangeable. Defer is the more conservative choice when several files have dependencies or a known order. Async allows a file to execute as soon as it is available, so execution order can vary with network timing.
Use async only when the script is genuinely independent of other scripts and of parser-time inline code. Analytics, widgets, or other external code may have their own documented loading requirements; follow those requirements rather than applying a global async rule. For application bundles with dependencies, begin with defer and verify behavior.
How to verify that WordPress actually deferred the file
Do not assume that a PHP call produced the desired tag. Verify the rendered page:
Rank #4
- Open a front-end page where the handle is enqueued.
- View the generated source or inspect the script element in browser developer tools.
- Find the script URL or handle and check that the tag contains the deferred strategy attribute.
- Confirm that the file appears only once and that its dependency files are present in an order consistent with your code.
- Exercise the page’s interactive features and watch the browser console for initialization or “is not defined” errors.
If the attribute is missing, check the WordPress version, the callback that enqueues the script, the exact handle passed to wp_script_add_data(), and whether another system rewrites the tag. A handle typo can leave the intended file unchanged while the rest of the page appears normal.
Render blocking javascript wordpress: why optimization plugins can conflict
Caching and optimization plugins may offer their own JavaScript deferral. Running that feature on top of WordPress’s native strategy can result in double processing or altered attributes. One support report describes a plugin’s deferral conflicting with WordPress strategy attributes; the practical lesson is to use one clearly owned deferral layer.
Choose one owner for the strategy
- Native WordPress: set the strategy in PHP and disable the optimization plugin’s equivalent feature for those handles.
- Optimization plugin: leave the PHP strategy unset for scripts managed by the plugin and configure exclusions there.
- Mixed setup: document which layer owns each handle, then test the final HTML because processing order can differ by page.
Do not evaluate the source PHP alone. The browser receives the result after all enqueue callbacks, dependency resolution, caching, minification, and tag rewriting have run.
Troubleshooting common breakage
The page reports that a function is undefined
This usually indicates that code ran before its library or bundle had executed. Check whether the library was deferred, whether an inline block still runs during parsing, and whether a dependent handle was left non-deferred. Restore the previous strategy for the shared library or move the dependent code into the same deferred chain, then retest.
A menu, form, or widget stops initializing
Inspect the console and identify the first failing script, not merely the last visible symptom. Confirm that the script’s declared dependencies are enqueued on that page and that an optimization plugin has not delayed, combined, or removed one of them. Exclude the smallest necessary handle rather than disabling all JavaScript optimization.
Best Value
- easy to use
- Free app
- Compatible with all devices
- It gives the best comparison between ten different hosts
The strategy works on one page but not another
Conditional enqueue logic may mean the handle, its dependencies, or an inline initializer exists only on certain templates. Compare the generated script tags on a working page and a failing page. Apply the strategy at the registration point used by both paths, or maintain separate, tested configurations where the dependency graph differs.
There is no visible performance improvement
Deferring a file does not guarantee a measurable result. The file may already be in the footer, another render-blocking resource may dominate, or the page may need that code immediately. Check the final HTML and the page’s actual critical path before adding more exceptions or changing unrelated scripts. No universal performance percentage should be expected from the API alone.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsA practical rollout checklist
- Confirm the site runs WordPress 6.3 or newer if you expect native strategy handling.
- Choose a script you control and record its dependencies and dependents.
- Set
'strategy' => 'defer'inwp_enqueue_script(), or usewp_script_add_data()after registration. - Use footer placement where appropriate and ensure the module/import-map placement caveat is satisfied.
- Do not include jQuery or other shared libraries until their consumers have been tested.
- Check for a caching or optimization plugin that also defers, combines, or rewrites scripts.
- Inspect the rendered tag for the expected attribute and verify that the file is not duplicated.
- Test logged-in and logged-out views, mobile layouts, forms, navigation, and any page-specific JavaScript.
- Keep a handle-level record of exclusions so a later optimization change does not silently reintroduce the problem.
What changed in WordPress 6.3, and what has not
WordPress 6.3 introduced the native strategy option for enqueued scripts, eliminating the need for a custom filter-based workaround on supported versions. The same release-era API recognizes the strategy metadata added with wp_script_add_data().
There is no established 2026 core API replacement in the material available for this guide. A proposal discussed in a plugin performance issue to combine native defer behavior with fetchpriority is not a WordPress core change. For current sites, the 6.3+ Scripts API remains the documented foundation: declare the strategy, respect dependencies, and test the final output.
Recommended decision path
- WordPress 6.3+ and you own the enqueue call: use the
$argsarray within_footerandstrategy. - WordPress 6.3+ and the handle is already registered: call
wp_script_add_data( $handle, 'strategy', 'defer' )after registration. - Older WordPress: know that the metadata call is ignored; plan an upgrade or use a separately tested mechanism rather than assuming defer is active.
- Shared or third-party script: map dependents first and avoid deferring it until all consumers tolerate post-parse execution.
- Optimization plugin already rewriting scripts: assign one deferral owner and verify the browser-facing markup.
The Bottom Line
For WordPress 6.3+, the reliable method is native: pass 'strategy' => 'defer' to wp_enqueue_script(), or attach the same strategy with wp_script_add_data() after registration. Preserve dependency order, be cautious with jQuery and shared third-party handles, and disable competing deferral features or exclude overlapping scripts in optimization plugins.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →




