|
1 |
| -# vue-server-renderer |
| 1 | +# Vue.js Server-Side Rendering Guide |
2 | 2 |
|
3 |
| -Hello baby |
| 3 | +## What is SSR? |
| 4 | + |
| 5 | +Vue.js is a framework for building client-side applications. By default, Vue components produce and manipulate DOM in the browser as output. However, it is also possible to render the same components into HTML strings on the server, send them directly to the browser, and finally "hydrate" the static markup into a fully interactive app on the client. |
| 6 | + |
| 7 | +A server-rendered Vue.js app can also be considered "isomorphic" or "universal", in the sense that the majority of your app's code runs on both the server **and** the client. |
| 8 | + |
| 9 | +## Why SSR? |
| 10 | + |
| 11 | +Compared to a traditional SPA (Single-Page Application), the advantage of SSR primarily lies in: |
| 12 | + |
| 13 | +- Better SEO, as the search engine crawlers will directly see the fully rendered page. |
| 14 | + |
| 15 | + 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. |
| 16 | + |
| 17 | +- 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. |
| 18 | + |
| 19 | +There are also some trade-offs to consider when using SSR: |
| 20 | + |
| 21 | +- 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. |
| 22 | + |
| 23 | +- 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. |
| 24 | + |
| 25 | +- 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. |
| 26 | + |
| 27 | +Before using SSR for your app, the first question you should ask it whether you actually need it. It mostly depends on how important time-to-content is for your app. For example, if you are building an internal dashboard where an extra few hundred milliseconds on initial load doesn't matter that much, SSR would be an overkill. However, in cases where time-to-content is absolutely critical, SSR can help you achieve the best possible initial load performance. |
| 28 | + |
| 29 | +We realize it could be quite challenging to build a server-rendered Vue app if you are not already familiar with webpack, Node.js and Vue itself. If you prefer a higher-level solution that provides a smoother on-boarding experience, you should probably give [Nuxt.js](http://nuxtjs.org/) a try. It's built upon the same Vue stack but abstracts away a lot of the complexities, and provides some extra features such as static site generation. However, it may not suit your use case if you need more direct control of your app's structure. And it would still be beneficial to read through this guide to better understand how things work together. |
| 30 | + |
| 31 | +If you believe your use case justifies the use of SSR, then let's dive in! |
0 commit comments