localize_script or rest api

You’d only use the REST API or AJAX if you didn’t know what data you needed until the script was run or there was some user interaction. If you already know the data you need based on page you’re on then you might as just pass that data with wp_localize_script(), otherwise you’re forcing the client to make a separate request once the page has loaded, slowing everything down.