Context: I'm building a popup widget. The html and css files are stored in S3. I need to get those files asynchronously and then continue with the rest of the logic.
In the code below, I'm getting the html file from S3 and setting the contents of a popup div to be equal to the contents of this file.
The issue: I have a lot more logic to handle the rest of the form. I'm currently using loadFormFunctions as the starting point to executing the remaining logic. loadFormFunctions contains many other functions that need to be executed.
Question: Is this best practice for executing the remaining code? Or is there a way to check if getFromS3 has resolved and then continue executing another function?
async function getFromS3() {
await fetch('someFileinS3.html', {
}).then((response) => {
return response.text()
}).then((text) => {
popup.innerHTML = "";
popup.innerHTML = text;
loadFormFunctions();
})
}
I realize the way I've laid this out might be confusing. Please let me know if you need me to rephrase.
await
and storing in local variables instead of usingthen
, I do not know. This question looks like a good fit for Code Review.