![]() doSomething ( ) // Fails, because it's not ready yet. Deferred scripts, however, wait until the DOMContentLoaded event to execute, and maintain ordering amongst themselves, thus offering good default performance characteristics (by giving the document a chance to render) while being suitable for a dependency management mechanism.ĭeferred scripts are usually created with the defer attribute: Async scripts execute as soon as they are fetched, thus not maintaining ordering, which means they're unfit for the purpose of managed dependencies (and exhibit generally unpredictable performance). ![]() While the enqueue mechanism uses the default behaviour blocking scripts, two other timing options exist on the web: deferred scripts and async scripts. However, this is not an ideal solution from a performance point of view, since from an API perspective it can lead to problems if dependencies and dependants have different values and expectations for $in_footer. One way of avoiding some of these issues is to move the scripts to the footer, which can be done with the $in_footer parameter in wp_enqueue_script. ![]() This means that if a blocking script is in, for example, the document will remain completely unrendered while the script is fetched, parsed, compiled, and executed, likely resulting in worse scores in metrics like First Paint, First Contentful Paint, and Largest Contentful Paint. Blocking scripts are problematic for performance, because they block document parsing and rendering when they're reached.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |