Search code examples
axiosgoogle-chrome-devtoolspagespeednuxt.js

how to use "preconnect" and "dns-prefetch" with Axios


how can i fix this with Axios, Are there any parameters ?

axios.get('/slug', { params })

Preconnect to required origins Consider adding preconnect or dns-prefetch resource hints to establish early connections to important third-party origins. Learn more.

enter image description here

why chrome audit declares this opportunity when this url does not exist in the source code

https://immobiliere-essaouira.graines-digitales.fr/


Solution

  • All resource hints can be used only as attributes on a <link> element. You can read about what they do and how for example here

    So there is nothing you can do directly in JavaScript (except of course adding the attribute to existing link dynamically based on user action)

    If your are requesting something using Axios from domain https://api.my-app.com, just including <link rel="preconnect" href="https://api.my-app.com" /> into your page should be enough...