customization – wp_enqueue_script JS code runs too late (after user begins interacting)
The issue is that we need to replace some HTML based on the user’s user agent string but by the time the JS code is loaded and runs, the user is already interacting with the page.
Is there some way to ensure
wp_enqueue_script will enqueue a script as early as possible? We’re already enqueuing without any dependency array, but users are often able to interact with the page before a simple replacement of a URL is done (done based on the Browser user agent string.)
Or is there some way we could do said replacement server-side to circumvent this?
For example we might have a link like
https://example.org/download-for-windows by default and we need to replace it with
https://example.org/download-for-linux when a Linux user-agent is detected.