The newest WordPress update, version 6.4, brings improvements to how scripts load on the front end, resulting in faster page load times and improved site performance.
These changes are part of WordPress’s core and bundled themes. They optimize the process of loading scripts by using two attributes: “defer” and “async.”
The “async” attribute instructs the browser to load scripts in the background, while “defer” loads them after the rest of the page has loaded. These enhancements greatly accelerate the time it takes for a page to become interactive.
Improved Page Loading Speed through Intelligent Script Handling
In previous versions of WordPress, JavaScript files within themes and plugins didn’t load asynchronously, causing them to block other downloads and slow down page rendering as they were fetched and executed.
With this update, WordPress ensures faster page loading for website visitors. In particular, it enhances the Core Web Vitals‘ first contentful paint (FCP) metric, which determines how quickly the page initially appears.
Behind the Scenes: What did WordPress do?
To achieve these improvements, JavaScript files for elements such as navigation menus and embedded media from WordPress.com have now been updated with the ‘defer’ attribute when enqueued. The ‘wp-embed’ script used for displaying embedded posts also now benefits from ‘defer.’
In the past, the ability to add these attributes was not standardized. However, with the introduction of a dedicated API in WordPress 6.3 and its full implementation in 6.4, developers now have a standardized method for controlling when their scripts load.
Read More: Apple plans to upgrade the App Store’s search engine: Truth or Just a Rumor?
Furthermore, this update has moved the majority of deferred scripts back into the <head> section since they no longer hinder rendering. This adjustment allows the browser to discover and cache these scripts earlier, thus enhancing overall performance.
A few lower-priority scripts, such as the one for comment replies, remain in the footer but are loaded asynchronously using ‘async’ to run in parallel with other resources.
How is it beneficial for Website Visitors?
For website visitors, the update translates into faster loading times for pages containing WordPress content. There will be less ‘jank,’ or shifting around of page elements, after the initial page load.
These changes establish the foundation for even more substantial optimizations in the future.