Skip to content

cn #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 59 commits into from
Closed

cn #2

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
346d96b
update cn
dear-lizhihua Apr 27, 2017
d6e3bef
update title
dear-lizhihua Apr 28, 2017
b6d9516
update title
dear-lizhihua Apr 28, 2017
435f75d
Fix nodeExternals require typo (#4)
obertrand Apr 28, 2017
67740e9
:bug: Fix rendered example (#6)
Snugug Apr 30, 2017
3206947
Update bundle-renderer.md (#8)
Alex-Sokolov Apr 30, 2017
0d6345c
fix link to clientManifest (#7)
pi0 Apr 30, 2017
f0ed9f5
improve information regarding bundle global context
yyx990803 May 1, 2017
df122dc
Update data.md (#11)
jakwuh May 1, 2017
047366b
Fix typo in bundle-renderer.md (#12)
Alex-Sokolov May 1, 2017
39e6e25
document runInNewContext changes in 2.3.1
yyx990803 May 2, 2017
e86b8ee
update head management
yyx990803 May 2, 2017
2325c84
Merge branch 'master' into cn
dear-lizhihua May 2, 2017
2bffc9e
/en/universal.md 翻译
dear-lizhihua May 2, 2017
ae5de26
/en/structure.md 翻译
dear-lizhihua May 3, 2017
90d8bee
Update routing.md (#14)
dear-lizhihua May 3, 2017
e122f57
[READY TO MERGE] Russian translation (#13)
Alex-Sokolov May 6, 2017
ad6c62e
Update data.md (#18)
olayinkaos May 9, 2017
e392831
document how to code-split store modules
yyx990803 May 12, 2017
ea55c95
add a note about side effects in created/beforeCreate
yyx990803 May 12, 2017
d865a28
[RU] Update translation (#21)
Alex-Sokolov May 12, 2017
ebc1dbf
Merge branch 'master' into cn
dear-lizhihua May 16, 2017
7afc8b9
add en weblinks
dear-lizhihua May 16, 2017
5beb5d3
Fix two errors with the clientManifest (#19)
danieldiekmeier May 16, 2017
3563338
Update bundle-renderer.md (#17)
morkro May 16, 2017
67392aa
fix /en/basic.md
dear-lizhihua May 16, 2017
b70589c
/en/routing.md 翻译
dear-lizhihua May 16, 2017
1c17b0b
Update docs to have double vs triple quoted meaning in for interpolat…
Austio May 18, 2017
ac39d56
[RU] Update translation (#27)
Alex-Sokolov May 19, 2017
c4ac88d
Add some tick for consistency (#28)
MachinisteWeb May 22, 2017
90de581
fix example (#30)
riophae May 22, 2017
8c67c6d
fix example (#32)
riophae May 22, 2017
6219044
[RU] Update with last fixes (#31)
Alex-Sokolov May 22, 2017
ee8a81b
Merge branch 'master' into cn
dear-lizhihua May 23, 2017
041a0b6
/en/data.md 部分翻译
dear-lizhihua May 23, 2017
41377f9
/en/README.md 部分翻译
dear-lizhihua May 24, 2017
75ed504
/en/README.md 翻译
dear-lizhihua May 24, 2017
3f926ce
/en/data.md 翻译
dear-lizhihua May 25, 2017
b12cd08
Typo fix (#33)
MachinisteWeb May 27, 2017
659bc2a
Merge branch 'master' into cn
dear-lizhihua May 28, 2017
af12c45
/en/hydration.md 翻译
dear-lizhihua May 28, 2017
f8d5161
/en/bundle-renderer.md 翻译
dear-lizhihua May 29, 2017
36c7842
/en/css.md 部分翻译
dear-lizhihua May 30, 2017
043e298
/en/css.md 翻译
dear-lizhihua May 31, 2017
43f80d9
/en/caching.md 翻译
dear-lizhihua May 31, 2017
18c2765
/en/streaming.md 翻译
dear-lizhihua Jun 1, 2017
7fe409c
/en/api.md 部分翻译
dear-lizhihua Jun 1, 2017
5071c09
/en/api.md 翻译
dear-lizhihua Jun 2, 2017
14499f5
/en/api.md 翻译
dear-lizhihua Jun 2, 2017
779373a
Doc EN: hydratation.md tick consistency (#38)
MachinisteWeb Jun 2, 2017
60caca0
Fix hello and webpack cases (#39)
MachinisteWeb Jun 5, 2017
f91f864
您->你
dear-lizhihua Jun 5, 2017
4dbfd60
Merge branch 'master' into cn
dear-lizhihua Jun 5, 2017
ba1814e
/en/build-config.md 部分翻译
dear-lizhihua Jun 5, 2017
d002b92
/en/build-config.md 部分翻译
dear-lizhihua Jun 6, 2017
e41da11
/en/build-config.md 翻译
dear-lizhihua Jun 6, 2017
3e41425
/en/head.md 翻译
dear-lizhihua Jun 6, 2017
0647466
fix
dear-lizhihua Jun 13, 2017
c3eecbb
fix
dear-lizhihua Jun 13, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LANGS.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* [English](en/)
* [Русский](ru/)
52 changes: 28 additions & 24 deletions en/README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
# Vue.js Server-Side Rendering Guide
# Vue.js 服务器端渲染指南

> **Note:** this guide requires the following minimum versions of Vue and supporting libraries:
> **注意:** 本指南需要最低为如下版本的 Vue,以及以下 library 支持:
> - vue & vue-server-renderer >= 2.3.0
> - vue-router >= 2.5.0
> - vue-loader >= 12.0.0 & vue-style-loader >= 3.0.0

> If you have previously used Vue 2.2 with SSR, you will notice that the recommended code structure is now [a bit different](./structure.md) (with the new [runInNewContext](./api.md#runinnewcontext) option set to `false`). Your existing app should continue to work, but it's recommended to migrate to the new recommendations.
> 如果先前已经使用过 Vue 2.2 的服务器端渲染(SSR),您应该注意到,推荐的代码结构现在[略有不同](./structure.md)(使用新的 [runInNewContext](./api.md#runinnewcontext) 选项,并设置为 `false`)。现有的应用程序可以继续运行,但建议您迁移到新的推荐规范。

## What is Server-Side Rendering (SSR)?
## 什么是服务器端渲染(SSR)?

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.
Vue.js 是构建客户端应用程序的框架。默认情况下,可以在浏览器中输出 Vue 组件,进行生成 DOM 和操作 DOM。然而,也可以将同一个组件渲染为服务器端的 HTML 字符串,将它们直接发送到浏览器,最后将静态标记"混合"为客户端上完全交互的应用程序。

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.
服务器渲染的 Vue.js 应用程序也可以被认为是"同构"或"通用",因为应用程序的大部分代码都可以在**服务器**和**客户端**上运行。

## Why SSR?
## 为什么使用服务器端渲染(SSR)?

Compared to a traditional SPA (Single-Page Application), the advantage of SSR primarily lies in:
与传统 SPASingle-Page Application - 单页应用程序)相比,服务器端渲染(SSR)的优势主要在于:

- Better SEO, as the search engine crawlers will directly see the fully rendered page.
- 更好的 SEO,由于搜索引擎爬虫抓取工具可以直接查看完全渲染的页面。

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.
请注意,截至目前,Google Bing 可以很好对同步 JavaScript 应用程序进行索引。在这里,同步是关键。如果您的应用程序初始展示 loading 菊花图,然后通过 Ajax 获取内容,抓取工具并不会等待异步完成后再行抓取页面内容。也就是说,如果 SEO 对你的站点至关重要,而你的页面又是异步获取内容,则你可能需要服务器端渲染(SSR)解决此问题。

- 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.
- 更快的内容到达时间(time-to-content),特别是对于缓慢的网络情况或运行缓慢的设备。无需等待所有的 JavaScript 都完成下载并执行,才显示服务器渲染的标记,所以你的用户将会更快速地看到完整渲染的页面。通常可以产生更好的用户体验,并且对于那些「内容到达时间(time-to-content)与转化率直接相关」的应用程序而言,服务器端渲染(SSR)至关重要。

There are also some trade-offs to consider when using SSR:
使用服务器端渲染(SSR)时还需要有一些权衡之处:

- 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.
- 开发条件所限。浏览器特定的代码,只能在某些生命周期钩子函数(lifecycle hook)中使用;一些外部扩展库(external library)可能需要特殊处理,才能在服务器渲染应用程序中运行。

- 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.
- 涉及构建设置和部署的更多要求。与可以部署在任何静态文件服务器上的完全静态单页面应用程序(SPA)不同,服务器渲染应用程序,需要处于 Node.js server 运行环境。

- 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.
- 更多的服务器端负载。在 Node.js 中渲染完整的应用程序,显然会比仅仅提供静态文件的 server 更加大量占用 CPU 资源(CPU-intensive - CPU 密集),因此如果您预料在高流量环境(high traffic)下使用,请准备相应的服务器负载,并明智地采用缓存策略。

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.
在对您的应用程序使用服务器端渲染(SSR)之前,您应该问第一个问题是否真的需要它。这主要取决于内容到达时间(time-to-content)对应用程序的重要程度。例如,如果您正在构建一个内部仪表盘,初始加载时的额外几百毫秒并不重要,这种情况下去使用服务器端渲染(SSR)将是一个小题大作之举。然而,内容到达时间(time-to-content)要求是绝对关键的指标,在这种情况下,服务器端渲染(SSR)可以帮助您实现最佳的初始加载性能。

## SSR vs Prerendering
## 服务器端渲染 vs 预渲染(SSR vs Prerendering)

If you're only investigating SSR to improve the SEO of a handful of marketing pages (e.g. `/`, `/about`, `/contact`, etc), then you probably want __prerendering__ instead. Rather than using a web server to compile HTML on-the-fly, prerendering simply generates static HTML files for specific routes at build time. The advantage is setting up prerendering is much simpler and allows you to keep your frontend as a fully static site.
如果您调研服务器端渲染(SSR)只是用来改善少数营销页面(例如 `/`, `/about`, `/contact` 等)的 SEO,那么您可能需要__预渲染__。无需使用 web 服务器实时动态编译 HTML,而是使用预渲染方式,在构建时(build time)简单地生成针对特定路由的静态 HTML 文件。优点是设置预渲染更简单,并可以将您的前端作为一个完全静态的站点。

If you're using Webpack, you can easily add prerendering with the [prerender-spa-plugin](https://github.com/chrisvfritz/prerender-spa-plugin). It's been extensively tested with Vue apps - and in fact, [the creator](https://github.com/chrisvfritz) is a member of the Vue core team.
如果您使用 webpack,您可以使用 [prerender-spa-plugin](https://github.com/chrisvfritz/prerender-spa-plugin) 轻松地添加预渲染。它已经被 Vue 应用程序广泛测试 - 事实上,[作者](https://github.com/chrisvfritz)Vue 核心团队的成员。

## About This Guide
## 关于此指南

This guide is focused on server-rendered Single-Page Applications using Node.js as the server. Mixing Vue SSR with other backend setups is a topic of its own and is not covered in this guide.
本指南专注于,使用 Node.js server 的服务器端单页面应用程序渲染。将 Vue 服务器端渲染(SSR)与其他后端设置进行混合使用,是其它后端自身的一个主题,本指南不包括在内。

This guide will be very in-depth and assumes you are already familiar with Vue.js itself, and have decent working knowledge of Node.js and webpack. If you prefer a higher-level solution that provides a smooth out-of-the-box 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 boilerplate, 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. Regardless, it would still be beneficial to read through this guide to better understand how things work together.
本指南将会非常深入,并且假设您已经熟悉 Vue.js 本身,并且具有 Node.js webpack 的相当不错的应用经验。如果您具有更高级解决方案,可以提供一个平缓的开箱即用体验,您应该去尝试使用 [Nuxt.js](http://nuxtjs.org/)。它建立在同等的 Vue 技术栈之上,但抽象出很多模板,并提供了一些额外的功能,例如静态站点生成。但是,如果您需要更直接地控制应用程序的结构,Nuxt.js 并不适合这种使用场景。无论如何,阅读本指南将更有助于更好地了解一切如何运行。

As you read along, it would be helpful to refer to the official [HackerNews Demo](https://github.com/vuejs/vue-hackernews-2.0/), which makes use of most of the techniques covered in this guide.
当您阅读时,参考官方 [HackerNews Demo](https://github.com/vuejs/vue-hackernews-2.0/) 将会有所帮助,此示例使用了本指南涵盖的大部分技术。

Finally, note that the solutions in this guide are not definitive - we've found them to be working well for us, but that doesn't mean they cannot be improved. They might get revised in the future - and feel free to contribute by submitting pull requests!
最后,请注意,本指南中的解决方案不是限定的 - 我们发现它们对我们来说很好,但这并不意味着无法继续改进。可能会在未来持续改进,欢迎通过随意提交 pull request 作出贡献!

***

> 原文:https://ssr.vuejs.org/en/
30 changes: 15 additions & 15 deletions en/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
- [Basic Usage](basic.md)
- [Writing Universal Code](universal.md)
- [Source Code Structure](structure.md)
- [Routing and Code-Splitting](routing.md)
- [Data Pre-fetching and State](data.md)
- [Client Side Hydration](hydration.md)
- [Introducing Bundle Renderer](bundle-renderer.md)
- [Build Configuration](build-config.md)
- [CSS Management](css.md)
- [Head Management](head.md)
- [Caching](caching.md)
- [Streaming](streaming.md)
- [API Reference](api.md)
- [基本用法](basic.md)
- [编写通用代码](universal.md)
- [源码结构](structure.md)
- [路由和代码分割](routing.md)
- [数据预取和状态](data.md)
- [客户端混合](hydration.md)
- [Bundle Renderer 指引](bundle-renderer.md)
- [构建配置](build-config.md)
- [CSS 管理](css.md)
- [Head 管理](head.md)
- [缓存](caching.md)
- [流式渲染](streaming.md)
- [API 参考](api.md)
- [createRenderer](api.md#createrendereroptions)
- [createBundleRenderer](api.md#createbundlerendererbundle-options)
- [Class: Renderer](api.md#class-renderer)
- [Class: BundleRenderer](api.md#class-bundlerenderer)
- [Renderer Options](api.md#renderer-options)
- [Renderer 选项](api.md#renderer-options)
- [template](api.md#template)
- [clientManifest](api.md#clientmanifest)
- [inject](api.md#inject)
Expand All @@ -24,4 +24,4 @@
- [basedir](api.md#basedir)
- [cache](api.md#cache)
- [directives](api.md#directives)
- [Webpack Plugins](api.md#webpack-plugins)
- [webpack 插件](api.md#webpack-plugins)
Loading