JavaScript Examples - Respond with Another Site
Answer an incoming request with content fetched from a different website, serving it transparently from Azion’s global network. Use this pattern for temporary redirects or to proxy another site’s response without issuing an HTTP redirect that changes the URL in the browser.
addEventListener("fetch", event => { return event.respondWith( fetch("https://www.azion.com/en/") ) })How it works
The function listens for the fetch event with addEventListener. Instead of building a local Response, it calls fetch() to request a resource from another origin and passes the resulting promise straight to event.respondWith(). Azion’s global network then waits for that upstream response and relays it back to the client as the answer to the original request. Because the fetch happens on a distributed architecture, the substituted content is served close to the user while the visitor’s address bar keeps the original URL.