# Server-Side Rendering See https://docsify.now.sh Repo in https://github.com/docsifyjs/docsify-ssr-demo ## Why SSR? - Better SEO - Feeling cool ## Quick start Install `now` and `docsify-cli` in your project. ```bash npm i now docsify-cli -D ``` Edit `package.json`. If the documentation in `./docs` subdirectory. ```json { "name": "my-project", "scripts": { "start": "docsify start . -c ssr.config.js", "deploy": "now -p" }, "files": [ "docs" ], "docsify": { "config": { "basePath": "https://docsify.js.org/", "loadSidebar": true, "loadNavbar": true, "coverpage": true, "name": "docsify" } } } ``` !> The `basePath` just like webpack `publicPath`. We can use local or remote files. We can preview in the local to see if it works. ```bash npm start # open http://localhost:4000 ``` Publish it! ```bash now -p ``` Now, You have a support for SSR the docs site. ## Custom template You can provide a template for entire page's HTML. such as ```html docsify ``` The template should contain these comments for rendered app content. - `` - `` ## Configuration You can configure it in a special config file, or `package.json`. ```js module.exports = { template: './ssr.html', maxAge: 60 * 60 * 1000, // lru-cache config config: { // docsify config } } ``` ## Deploy for your VPS You can run `docsify start` directly on your Node server, or write your own server app with `docsify-server-renderer`. ```js var Renderer = require('docsify-server-renderer') var readFileSync = require('fs').readFileSync // init var renderer = new Renderer({ template: readFileSync('./docs/index.template.html', 'utf-8'), config: { name: 'docsify', repo: 'docsifyjs/docsify' } }) renderer.renderToString(url) .then(html => {}) .catch(err => {}) ```