Adding defer to your scripts is one of the cheapest speed wins on a WordPress site. It is also the setting most likely to break a menu, a slider or a checkout field. This post explains why, with a small example, and shows a safe way to roll it out.
Disclosure: I'm part of the team behind NodeThemes Cache AI, a free WordPress cache plugin that tests changes like this one. The technique below works with or without it.
What defer actually changes
A classic <script src> in the <head> blocks parsing: the browser downloads and runs it before it builds the rest of the page. With defer , the browser keeps parsing and runs the script later. According to MDN , deferred scripts:
run after the document has been parsed, before DOMContentLoaded
run in the order they appear
only apply to external scripts ( defer on an inline script does nothing)
Attribute Blocks parsing?…