What to do so that page loads when API calls are finished?
https://snazzy-tiramisu-4033f2.netlify.app/
My JS lags behind since it is dealing with API, and first thing that loads is just the regular HTML I have, and then it process the API.
What to do so that it loads the finished page?
I also think the way I setup my functions are slowing the code down, but I'm not sure. It goes something like this --->
You can check the actual code in the link of course.
11 Replies
u can put a loading screen
that's what every webpage does
the way you'd do it
`
@glutonium I'm a bit confused and can't figure out how to apply that example into my code. 😦
Do I need to design loading screen?
Just add massive blur?
What is loading()?
yes
depends on your choice
function that turns loading screen on or off
Why you need to read from an API everytime the site loads? Does the content change every hour or something like that?
personally I always feel like a loading screen is a last resort. Is there some way you can rearrange the js so the api call happens sooner? Or move the api call into the HTML in a script tag?
well in that regard what comes to me the very first is using the script tag within the head tag without the defer attribute
the perhaps you can export the data and then within another script tag (with defer attr) , import the data and show it
not sure about it tho
It shows time based on your coutry via your IP address. So when you first load the page, it needs to first read all those API calls to show your time. I can ofc just plant random placeholder numbers, but the "problem" is that background image also changes based on the time of the day and it is distracting and ugly if it changes after you are already on the page, instead of being ready when you load in.
That is what I would love to know. I know for a fact that my JS code and function calling is sloppy and unefficient, I just don't know how to properpy rearange it.
I'll look up the defer script part to see how it works. And maybe come back to the project once I know more about JS and proper function/API calling.
outside the JS stuff maybe throw a more image appropriate
background-color
behind your full screen background-image
s. Right now you have a gray behind both the day and night images. Which doesn't feel native to either of the images. If you had for example a black-ish background-color
behind the mostly black night image, the load in of that image wouldn't be as jarring.if all it does is show time based on IP, just show time based on the computer's local time?
It shows more info based on it if you click more. I linked the project. Also, it is a FrontEndMentor project that serves to practice API, so it is not for efficiency. xD
You are right. I should do that.
I'm just more focused on API/JS on this one, and I'm just doing HTML/CSS to be "Good enough". I should also just go and watch/read more JS tutorials/guides on how to properly write functions since I just know I'm slowing my code down a lot, even if it is not big. xD
If you want to make it a JS thing maybe load the background images in JS so that they are ready for the browser to just drop in immediately when the
background-image
code gets added to the html?