Intro to Nuxt
Tags: javascript, nuxt, vue, webdev
Published: 2019-08-23 13:16:42

---
title: Intro to Nuxt
published: true
description: What I picked up learning Nuxt in the last week
tags: javascript, nuxt, vue, webdevelopment
---

Nuxt is a server side rendering framework built on top of Vue. 

You might think 'but Vue is a framework, why a framework for a framework?'

The thing is Vue is beautiful and easy to pick up and use, but Vue Single Page Applications (SPA) -as other front end framework SPAs- have problems with Search Engine Optimization (SEO) because  when a SPA url is visited, the server sends the index.html which has no content. The pages are rendered by Javascript on the browser. This reduces server load but search engine crawlers are not very good at waiting for JavaScript to render content.

Enter Server Side Rendering (SSR). SSR enables us to render our content on the fly before it hits the browser. When a user and / or crawler hits a server side rendered web application url, the server sends a fully rendered page the first time, subsequent navigation is done on the client as with regular SPAs.

This has lots of advantages and disadvantages. 

Here from the <a href="https://ssr.vuejs.org/#what-is-server-side-rendering-ssr">Vue Docs</a>:


Pros:

>Better SEO, as the search engine crawlers will directly see the fully rendered page.

>Note that as of now, Google and Bing can index synchronous JavaScript applications just fine. Synchronous being the key word there. If your app starts with a loading spinner, then fetches content via Ajax, the crawler will not wait for you to finish. This means if you have content fetched asynchronously on pages where SEO is important, SSR might be necessary.

>Faster time-to-content, especially on slow internet or slow devices. Server-rendered markup doesn't need to wait until all JavaScript has been downloaded and executed to be displayed, so your user will see a fully-rendered page sooner. This generally results in better user experience, and can be critical for applications where time-to-content is directly associated with conversion rate.

Cons:

>Development constraints. Browser-specific code can only be used inside certain lifecycle hooks; some external libraries may need special treatment to be able to run in a server-rendered app.

>More involved build setup and deployment requirements. Unlike a fully static SPA that can be deployed on any static file server, a server-rendered app requires an environment where a Node.js server can run.

>More server-side load. Rendering a full app in Node.js is obviously going to be more CPU-intensive than just serving static files, so if you expect high traffic, be prepared for corresponding server load and wisely employ caching strategies.


If a Server Side Rendered Vue App serves your purpose <a href="https://nuxtjs.org">Nuxt</a> makes this a breeze.

Nuxt makes the whole process as simple as possible. You only need to run 'npx create-nuxt-app' and you have a SSR app ready. 

Nuxt introduces a folder structure that makes it easy to work with it. Your pages are stored in a pages folder and Nuxt adds them to the router automatically.

Your plugins are contained in a plugins folder and are run before Vue is booted.

There is a huge community around it and lots of <a href="https://github.com/nuxt-community/awesome-nuxt#modules">modules</a> to handle most of the everyday problems.

Here's a small <a href="https://honest-parrot.herokuapp.com">project</a> I made with it, Laravel, and TailwindCSS. The code for the project is on github (<a href="https://github.com/ekediala/parrot-api">laravel api</a> and <a href="https://github.com/ekediala/honest-parrot">nuxt</a> frontend).