customization – wp_enqueue_script JS code runs too late (after user begins interacting)

Question

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.

0
Slbox 2 weeks 2022-07-27T18:17:51-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse