SPA w/ SEO or SSG + nitro?
i'm creating a SPA and i've opted to use nuxt because of the ease of development (especially for the frontend devs in my team, that automatically get an up to date server when they pull)
my expectation was that the data from
useSeoMeta
from app.vue
would be included in the build even with ssr: false
, but apparently all seo meta data is disregarded in that case (https://stackoverflow.com/questions/74070241/what-is-the-difference-between-ssrfalse-vs-targetstatic-in-nuxtjs)
so i've tried to use SSG and running nitro separately, but i keep running into problems..
i've been reading about it the entire afternoon and evening. it seems like such a basic usecase, but i can't find anything about it. i feel like i'm missing something obvious. any pointers appreciatedStack Overflow
What is the difference between 'ssr:false' vs 'target:static' in Nu...
To generate a static site using NuxtJS, it seems there are 2 options to set: ssr:false and target:static inside the NuxtJS config file (nuxt.config.js) which practically do the sme thing? Why both of
26 Replies
but apparently all seo meta data is disregarded in that caseYup, except the defaults from your nuxt config ssr: true (default) + using
nuxt generate
is the easiest way to go there
you can also only prerender the sites necessarythanks that solves the SPA
ssr: false
the SSG case with nuxt generate
is more interesting and applicable in my case thought, but i'm having some issues, i'll post a new thread
here is one of the problems with nuxt generate
: https://discord.com/channels/473401852243869706/1215088275409076274
how to run the nitro backend and serve the static output in parallel?nuxt build + setting prerender routes đ
i think there is a misunderstanding.
you were talking about
nuxt generate
(aka SSG), and i was asking about serving the SSG static output along with running the nitro server
do you mean setting prerender routes on a per route basis? i want all routes to be prerendered. nuxi build --prerender
seem more appropriate in that case, but that is experimental https://nuxt.com/docs/api/commands/build
i feel like i'm trying to achieve a very basic usecase, but it feels like i'm fighting nuxt to do something it's not supposed todo you mean setting prerender routes on a per route basis? i want all routes to be prerendered. nuxi build --prerender seem more appropriate in that case, but that is experimental https://nuxt.com/docs/api/commands/build--prerender seems like a decent option. You can also configure to prerender all routes that the crawler can find at build time
i feel like i'm trying to achieve a very basic usecase, but it feels like i'm fighting nuxt to do something it's not supposed toNo, this is an absolutely reasonable approach âşď¸
i'll try to keep my sanity, thanks for your help!
no problem at all!
BTW: It is not necessary to prerender all routes if you want an SPA
it is enough to provide an index.html and "forward" everything onto that through your platform (e.g. netlify and vercel do that by default with a 404 or 200.html)
you only need to prerender all if you need SSG and the content in the HTMl
yea
the benefit of prerendering is that pages can have their one meta tags for search engine results
essentials i have a SPA part and a static part
/ (SPA)
/somePage (frontend routed)
/help/someTopic (static with custom meta tags)
the benefit of prerendering is that pages can have their one meta tags for search engine resultsYes, but they are static then unless you use some
ClientOnly
components in there to make a part of it non-staticyes i do that
i also have a custom loading indicator.. i'd like to use the default
~/app/spa-loading-template.html
but unforunately that is only available when using ssr: false
, which is not what i want, because.. well you know what happens, it's not SSR-ed, hence no custom meta tags on the routeswell you know what happens, it's not SSR-ed, hence no custom meta tags on the routesYes, that's why SSR is helpful đ I wonder, why not going with dynamic SSR then?
i'll try to break it down by what my goal is and by what i gathered about the features that are offered by the different approaches
my goal
SPA part of the site
đŻ static small size initial html (to show something as soon as possible)
đŻ loading indicator (this is not really a goal, more like a necessary evil to show something as soon as possible)
đŻ api (nitro)
đŻ meta tags for "/" route
static part of the site
đŻ static initial html
đŻ custom meta tags per route
approaches
SPA
âď¸ static small size initial html
âď¸ loading indicator (~/app/spa-loading-template.html)
âď¸ api (nitro)
âď¸ meta tags for "/" route
â custom meta tags per route
SSG
âď¸ static initial html
âď¸ custom meta tags per route
â api (nitro) (?)
dynamic SSR
â static initial html (to show something as soon as possible)
âď¸ custom meta tags per route
âď¸ api (nitro)
â SSR performance paranoia (currently 60k users, aiming for millions very soon)
â SSR feels like losing ownership over network traffic
prerender SSR
âď¸ static initial html with control over size through
ClientOnly
â needs custom loading indicator
âď¸ custom meta tags per route
âď¸ api (nitro)
as you can see the downsides of dynamic SSR are more subjective than objective
for a side project dynamic SSR would be just fine, but for this project i prefer to eliminate uncertaintieswhat did you end up choosing
well as only 1 of the options has no â blockers, i chose:
prerender SSR all pages with
<ClientOnly>
in "SPA" pages + custom loading screen
this allows custom SEO meta tags per route and control over static initial html size
static small size initial html for "SPA" pages
static large size initial html for static pagesThanks, so does this allow each page to have its own meta date?
this allows custom SEO meta tags per routeyes per route aka page
So is your SSR set to true?
having troubles trying to implemet this
yes
hmm when I added
it broke my site lol
and getting following error on my slug.vue
that doesn't seem to be related, works for me
strange
only reason i can think of why prerender would not work if there are some useState refs that are not initialized at build time, and then when it tries to render some component it gets undefined and breaks
maybe let me check I am using Storyblok api to fetch data
the solution of a lot of things it to try to make it work in a sample project, then your can compare it to your main project