A project in our company was built using Astro and Svelte. In this project, API calls have to be made to a CMS to create blog posts dynamically. I would like a way for my clients to write blog posts, update the CMS(GraphCMS) and see that the website has created a new post.
-
1The creation of the post in the CMS would need to trigger a build on your host. With a static site generator this will never be instant or dynamic since the build process needs to run and be published by the host. If you want it to be truly dynamic you lose out on the SEO goodies SSGs get you and load speed increases for users, I usually do some client education to help them understand the post publishing delay. But if you really want dynamic post creation from the API call, Astro is the wrong tool for you. – JHeth Oct 11 '21 at 17:59
-
Hi @JHeth thank you so much for commenting, I was having a really hard time with this framework. I feel so relieved after getting your viewpoint on this. So, in essence, Astro isn't really the best tool for a website with content that is dynamically changing. I'll try and convey this to my team as well. – Aryan3212 Oct 11 '21 at 18:17
-
Clients always think they need dynamically changing content but most only add content once a week so SSG may be the actual best thing for the client (better SEO, faster load times). The difficulty is educating them on the benefits of what they need vs the convenience they want in post creation/editing. This talk should happen with your team first, then pitched to the client as an option to help their business. Here's a good article on the different hosting approaches https://dev.to/matfrana/server-side-rendering-vs-static-site-generation-17nf – JHeth Oct 11 '21 at 19:03
-
Thanks! Read the article and it explained the trade-offs for each paradigm quite effectively. – Aryan3212 Oct 13 '21 at 09:40
-
@JHeth do Astro supports incremental building? like if we want to add only one page, so there is no need to rebuild all the project. Is Astro capable to do such thing? – farynaa Mar 11 '23 at 09:28
2 Answers
There are 2 ways this can be done.
GraphCMS allows you to fire a web hook when an action is completed, in this case publish a blog post. You need to be hosting on something like Vercel or Netlify, but as long as your build system has a web hook trigger, it can accept the payload and rebuild the site. It'll take a minute or two to complete, but the person should be able to see the new content relatively quickly.
The other way, as other authors have suggested, is to use Astro with Svelte, React or some other client-side JS, and add a client-side router which can then fetch and render posts on the client. That's less efficient because your users will have to wait for data to be fetched, and it probably won't show up in search engines.

- 468
- 3
- 16
-
Hi! Thank you so much for answering. I actually figured this out after some time with the framework and GraphCMS. Adding client-side JS defeats the purpose of Astro but I still feel like your answer should be marked as correct since you gave more info. – Aryan3212 Jan 31 '22 at 11:44
-
Sorry it came a bit too late for your particular situation @Aryan3212, hope it helps someone else. – endymion1818 Jan 31 '22 at 15:55
If your company use Svelte, take a look at Sveltekit. See:
https://docs.astro.build/comparing-astro-vs-other-tools/#sveltekit-vs-astro
https://kit.svelte.dev/
https://svelteland.github.io/svelte-kit-blog-demo/create-your-blog/

- 433
- 4
- 12