Hi all, I wanted to know if it’s possible to update HTML content partially from the server-side with Express/Pug, more detail on my StackOverflow question: https://stackoverflow.com/questions/52296548/update-html-content-partially-with-express-server-side . Any help would greatly appreciated! I posted the question yesterday and no one’s been able to answer it for me…
I want to say yes you can, but I’m not sure I understand your situation 100%.
Your second snipped gives you and error, of course, because the server has already responded to the client with a
pug file and you can only send one response back per request. If you want to send another thing, AFAIK, the client needs to ask for it explicitly.
I don’t know if I understand correctly your problem. If you don’t want your users to wait for the content, just keep them distracted with a loading animation or something. Even if you pre-fetch the JSON data from the server on the first request, the user will need to wait for the content to load, either by seeing a blank screen (your particular case), a loading animation (what I’ve just proposed) or a browser waiting for the whole page to load (in case you pre-fetch the data from Express on the first request). Just like one StackOverflow user told you, if you have concerns about your server performance, demanding more work from it won’t help solving the issue. Also, IMHO, it’s better UX to render something to the users and letting them know that part of the content is being fetched than render nothing until everything has been completely loaded from the server.
Hope it helps.
This post was flagged by the community and is temporarily hidden.