7

I need to develop a website using laravel and nuxtjs. To my knowledege, SSR mode is one of the advanced feature of the nuxtjs but it requires to run the nuxt server. In other words, we need to deploy the laravel on the server like nginx and have to run the nuxt server by using npm run start. If we use SPA mode, nuxt generate static page into dist directory and we can simply merge it to laravel project and everything is done. We don't need to run the extra server.

This is my opinion so far. I am not sure whether or not it is true, so I can't decide which one to choose. First of all, I am not sure which one is really better. Second, I am not sure if SSR mode really requires to run the extra server.

I want to get advice from experts and make a decision. I'd be really grateful if you give me advice about this. Thanks in advance.

kissu
  • 40,416
  • 14
  • 65
  • 133
Chuck
  • 776
  • 5
  • 18
  • 4
    Your premise is incorrect. SSR and SPA are not mutually exclusive. SPA is Single-page application which means you use a client-side "router" to transition between pages without making requests in a server. SSR means there's a server that will pre-render the application HTML so it can be loaded by a browser on initial load and users (and web crawlers) won't have to wait for the JS to arrive before they see the page. You obviously can use both at the same time and both require some sort of server to run. SSR requires a server that can execute JS though while SPA needs a server to serve HTML – apokryfos Aug 04 '21 at 16:34
  • Thank you. Does it mean we need to run an extra server for SSR mode? Like `npm run start`? – Chuck Aug 04 '21 at 16:37
  • 2
    You need a server in both cases. However yes, in the case you have SSR you probably need a node.js server specifically (so using npm run start) while in the case where you only have an SPA then you only need to "compile" your javascript once and then serve it with a more basic server like e.g. an apache webserver or even an AWS S3 bucket. Also when you use SSR there might be some extra things to consider when writing code such as the `window` global might not be always available i.e. when the code is being rendered server-side – apokryfos Aug 04 '21 at 16:39
  • Thank you. That was crystal clear. I need to merge the compiled content to laravel project(Laravel is deployed on the nginx server). Do I still need to run the node sever? For SSR mode? – Chuck Aug 04 '21 at 16:40
  • 1
    That is an opinionated question, but I don't dare to flag it because I've been there and I know that's a very important decision to make which requires expertise. – Andre Goulart Aug 09 '21 at 05:28

1 Answers1

10

I recommend using SSG (target: static and ssr: true), this will give you SEO + speed and you will not need any server for this. Hence, hosting it on Netlify would be totally fine and free.
More info can be found here on the various steps: What's the real difference between target: 'static' and target: 'server' in Nuxt 2.14 universal mode?

Also, it all comes down to the drawbacks between SSR and SSG. More info can be found on Google. But if you don't have a first-page protected by a password or some back-office admin-only tool, SSG is usually the way to go.

kissu
  • 40,416
  • 14
  • 65
  • 133
  • 1
    Thank you. That's what I wanted to know. I wanted to use the SEO advantage of the SSR but did not want to run an extra server for that. – Chuck Aug 04 '21 at 16:53
  • So can it merge with Laravel and just use LAMP stack? – Fahmi Nov 03 '21 at 13:54
  • @Fahmi not sure what you're asking here. Add Nuxt inside of a Laravel app? Feel free to post a new question with all the details! – kissu Nov 03 '21 at 14:41
  • @kissu: i'm using SSG, and my SEO is dead :( All dynamics METAS are empty... – Vin Parker Jun 23 '22 at 19:47
  • @VinParker depends how you are doing those. Feel free to post a new question. – kissu Jun 23 '22 at 21:16
  • @kissu you right. Thanks for helping me ;) ;) https://stackoverflow.com/questions/72740872/dynamic-meta-seo-with-nuxt – Vin Parker Jun 24 '22 at 08:08