Is there a way to timeout the request sooner when a server is unavailable? I'm requesting a file via a script tag that times out after 21 seconds at which point the page tries to build without it. The status code for the request was 502:Bad Gateway while the server was down.
I am making a request from a server that is up and running fine to the server that is temporarily in a fledgling state. The normal request looks like this:
<script language="JavaScript" src="...someFileOnTheDownServer..."></script>
When the request tries to load the file, the loading of my primary page blocks and waits on the file that won't be served.
I can load the file asynchronously but that would also appear as a 'loading' status until 21 seconds passes. I would prefer to wait only 2-5 seconds in the attempt to retrieve the file.
This question looks rather similar but I thought that after 5 years there should be better alternatives, more questions on this subject, or a real solution to timeout the <script>
tag at a delay I specify.
I don't see a timeout
property yet on the MDN for the script tag. Does anyone have good experience with the HTML5 async
property? I would prefer to not use async
indefinitely as I would prefer the experience to have this file loaded and then for the page to render...just not wait 21 seconds to do it!
Update
In order for async to be an option, there needs to be a way to only execute some page-specific javascript code as soon as the requested file was loaded.
I tested the async
property and (for compatible browsers) the page renders without blocking and waiting for the file. However, I need some page-specific code to run once the page is loaded and not before. This answer seems to offer a solution but my preferred answer is in regards to being able to timeout the script loading at a specified interval.