how to reduce layout shift in astro

im currently in the process of rewriting my old personal site/blog in astro and i have almost finished it. but idk why the layout shift is so huge, please help deployed version: https://nexxel-dev-v2-6s310ftwp-nexxeln.vercel.app/
80 Replies
alrightsure
alrightsure•3y ago
I would think giving the body a width: 100% would help, but I can't test it in the browser since it resets the css every reload.
iDarkLightning
iDarkLightning•3y ago
Unrelated, ik, but your old one was so much better imo
nexxel
nexxelOP•3y ago
i will try this thanks what do you not like about the new one? i just wanted to have a depressed boring site tbh LUL old one got very bloated
alrightsure
alrightsure•3y ago
@nexxel how are you loading the font in? I think that's what's making the page jump on load.
nexxel
nexxelOP•3y ago
swap self hosted
alrightsure
alrightsure•3y ago
I'm not super well-versed in fonts but I'd probably mess with that. If you throttle the network and performance, you can see that it loads in another font first, then jumps to the correct layout once it loads in your font.
nexxel
nexxelOP•3y ago
yes that's what swap does but idk how to prevent the layout shift here
iDarkLightning
iDarkLightning•3y ago
Well if that was the goal... It just feels less vibrant and fun Nothing inherently bad with the design, but yk there's barely any design anyway so
nexxel
nexxelOP•3y ago
yeah that was kind of the goal :( i just want a site and not spend anymore time on it
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
yes me too just help with this layout shift
iDarkLightning
iDarkLightning•3y ago
What's wrong with just living the current one as it is
nexxel
nexxelOP•3y ago
it has gotten really bloated and i don't wanna use next
iDarkLightning
iDarkLightning•3y ago
Hm
Finn
Finn•3y ago
Of the top of my head. The fonts arnt being cached beacuse they must load in every route change
nexxel
nexxelOP•3y ago
how do i cache itttttt
benten
benten•3y ago
use remix Kappa
Finn
Finn•3y ago
Aaaaaaa ummmmm idk. Don't we have a Resident astro pro ben
nexxel
nexxelOP•3y ago
i don't wanna tag him 😭
Finn
Finn•3y ago
Neither 😭 Are you using font source or a font manually put in your repo?
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
manual oh wow thanks i'll try this but this will just cache it on the server right?
Finn
Finn•3y ago
Ohh yea that could wokr
nexxel
nexxelOP•3y ago
will that make the font load faster sorry idk how font caching works
Finn
Finn•3y ago
nah that will make your browser keep a cache of the font for longer but it should already cache the font already actually im on pc now i can have a little look
Finn
Finn•3y ago
currently your fonts are set to be re-fetch on every page load / route change
nexxel
nexxelOP•3y ago
ohhhh thats how i cache it on the client got it
Finn
Finn•3y ago
ye
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
wow that helped a lot thank you
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
no im not SSRing anything okay now how do i cache images so if a person on slow 3g visits, images will load faster
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Finn
Finn•3y ago
for these parts it looks like you could slap a min width on this. maybe using a clamp so its X width or 100vw whichever is smaller
nexxel
nexxelOP•3y ago
im not really fetching anything so i don't need a ssr adapter oh the whole body you mean?
Finn
Finn•3y ago
by this i mean the main body yea the stuff thats not background
nexxel
nexxelOP•3y ago
i added width: 100%
Finn
Finn•3y ago
got a preview?
needmorewood
needmorewood•3y ago
can we get code? cause for some reason fonts arent hitting cache so that should help actually nothing in the network tab is hitting cache nvm found it
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
needmorewood
needmorewood•3y ago
i fixed the email component flickering so far with client:load instead of visible, since it will always be visible on load anyways I've pushed many commits, couldn't get caching to hit on anything which is odd but the shift Is cause by the font and loading of it Removing that font I got cls down to 0
needmorewood
needmorewood•3y ago
Shoubhit Dash
nexxel • home
17 yo self-taught developer
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
yeah its due to the font :( ooo i was just using what the template came with this is interesting but im not sure how to implement this in astro that makes sense, so should i change the units to use rem
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
i can prolly do that yeah thanks
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
the font isn't loading at all for me fonts aren't a solved problem lolol this is so tough
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
wait lemme try another browser
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
the font did come through but it isn't applying for some reason https://nexxel-has.no-friends.xyz/chrome_FcZJEJiejF.png
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
oh cool thanks
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
dude i hate fonts :(
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
yeah i used chrome and brave not working on chromium based i guess :(
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
im using woff2
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
supported in all browsers i think how would this help?
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
yeah not what i want haha
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
yeah so weird, but thanks for the help!
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
shaaah
shaaah•3y ago
@nexxel Are you using woff2?
nexxel
nexxelOP•3y ago
yeah
shaaah
shaaah•3y ago
Ignore if you have tried these: 1. change swap to optional or fallback (try both) 2. use preload or preconnect in the <link> tag
nexxel
nexxelOP•3y ago
i don't want to use optional but i will try fallback thanks
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
shaaah
shaaah•3y ago
its the same 😅
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
shaaah
shaaah•3y ago
yes
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
shaaah
shaaah•3y ago
ah ya now that you put it together, yours is better for sure
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nexxel
nexxelOP•3y ago
i had it as swap too haha
shaaah
shaaah•3y ago
tbh, I never seen a layout shift this crazy. Its like the font is doing this purposely to mess with you, there is no other explanation to it
Want results from more Discord servers?
Add your server