Since WordPress 6.3 you can pass an array as the fifth argument of wp_enqueue_script() to set the loading strategy.
function lotgrafix_enqueue_deferred() {
wp_enqueue_script(
'lotgrafix-main',
get_template_directory_uri() . '/js/main.js',
array(),
'1.0.0',
array(
'strategy' => 'defer',
'in_footer' => true,
)
);
}
add_action( 'wp_enqueue_scripts', 'lotgrafix_enqueue_deferred' );
Use 'strategy' => 'async' for scripts that do not depend on other scripts or on the DOM order.