async function showNextPhoto( photoID ) { if ( ! cache[ photoID ] ) { cache[ photoID ] = apiClient.makeRequest({ url: "/index.cfm", params: { event: "api.sitePhotos.photo", index: photoID } }); } try { var response = await cache[ photoID ]; renderPhotoResponse( response ); // While the user is looking at the photo that we just rendered, let's // pre-cache more photos in the background. This way, by the time the // user goes to hit the NEXT PHOTO button, we'll (hopefully) have // already loaded that data and can render it immediately. Note that we // are NOT AWAITING this response since we don't care when it completes. preCacheNextPhoto( response.nextPhotoID ); } catch ( error ) { /// If something goes wrong, let's assume that the cached Promise is // problematic (a rejection) and delete it. This way, the next request // will attempt to fetch and re-cache it. delete( cache[ photoID ] ); console.warn( "Could not show next photo information." ); console.error( error ); } }