Async loading patterns
When to use the queue pattern
Use it when:- You add
asyncordeferto the<script>tag - The script is in
<head>butinit()is called in<body> - You’re loading via Google Tag Manager (GTM defers execution by default)
<script src="..."> and TryOnWidget.init() are at the end of </body> without async/defer, you don’t need this pattern.
The queue pattern
init() will be called exactly once, regardless of load order.