How to Defer JavaScript in WordPress Without Breaking Elementor Widgets? [closed]

I’m working on improving my WordPress website’s performance by deferring JavaScript. I tried using defer or async on my script tags, but this caused some Elementor widgets to stop working properly.

Here’s a simplified example of my current approach:

html
Copy
Edit

Is there a best practice for deferring JavaScript in WordPress while keeping Elementor (or other JS-heavy plugins) working as expected? Should I use specific hooks in functions.php or certain plugins to handle this?

Thanks!