Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 9c69f62

Browse files
committed
add Deborah's review
1 parent 8968e5e commit 9c69f62

File tree

1 file changed

+45
-34
lines changed

1 file changed

+45
-34
lines changed

public/docs/ts/latest/cookbook/production-deploy.jade

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ a#toc
99
* [Overview](#overview)
1010
* [Simplest deploy possible](#simplest-deploy-possible)
1111
* [Minimizing your payload](#minimizing-your-payload)
12-
* [Less files](#less-files)
12+
* [Fewer files](#fewer-files)
1313
* [Smaller files](#smaller-files)
1414
* [Template compilation](#template-compilation)
1515
* [Angular configuration](#angular-configuration)
@@ -28,7 +28,7 @@ a#overview
2828
After creating your brand new Angular app you'll want to put it online for the world to see.
2929

3030
Your development setup is optimized for build speed and rapid iteration, but when
31-
deployment to production you'll want to optimize for loading speed and payload size.
31+
deploying to production you'll want to optimize for loading speed and payload size.
3232

3333
In this chapter you'll see how to deploy your app right now, techniques to reduce your
3434
payload size, plus Angular and server configuration.
@@ -41,7 +41,7 @@ a#overview
4141
It is already working locally after all, so it should work live.
4242

4343
1. Copy over your local project folder to your server.
44-
2. In your server, edit `index.html` to have the right `<base href="/">` tag. If you are
44+
2. On your server, edit `index.html` to have the correct `<base href="/">` tag. If you are
4545
using a subfolder (e.g. `www.mysite.com/myapp/`) it should be `/myapp/` otherwise leave it as `/`.
4646
[More on this later](#angular-configuration).
4747
3. Configure your server to redirect requests for missing files to `index.html` instead.
@@ -50,6 +50,15 @@ a#overview
5050
And this is all you need to publish your app!
5151

5252
It's not a very good production deploy though.
53+
54+
For one, it has a lot of files that aren't even used when serving your site to users since it has
55+
all the development only packages.
56+
You could cut down the number of files by doing a production install (`npm install --production`),
57+
but only *after* compiling your Typescript files.
58+
59+
It also has a lot of small files. Each of those is going to take a whole round trip to get
60+
delivered to the browser, so it's not going to be that fast to load.
61+
5362
There's more you can do to make our site fast for users.
5463

5564
.l-main-section
@@ -61,28 +70,27 @@ a#overview
6170
There are several techniques for achieving a smaller payload for your app:
6271

6372
- Bundling: concatenating several modules into a single file (bundle).
64-
- Inlining: add html and css as strings inside components.
73+
- Inlining: adding html and css as strings inside components.
6574
- Minification: removing all unnecessary whitespace and optional tokens.
6675
- Uglification: rewriting code to use shorter variable/function names.
67-
- Dead Code Elimination: removing code/variables that will never used.
76+
- Dead Code Elimination: removing code/variables that are not used.
6877
- Tree shaking: removing unused module exports.
6978
- Ahead-of-Time (AoT) Compilation: pre-compiling Angular templates.
7079

7180
Each of these do different things overall, but they all work together and their effects
7281
compound on each other.
7382

74-
### Less files
75-
Bundling and inlining reduce your app's load time smaller by serving less files and thus
76-
less round trips.
83+
### Fewer files
84+
Bundling and inlining reduce your app's load time by serving fewer files and thus
85+
fewer round trips.
7786
For small files, the overwhelming majority of time it takes to get it is not spent downloading,
7887
but rather communicating with the server and coordinating the transfer.
7988
You can read more about resource timings in the
8089
[Chrome DevTools Network Performance page](https://developers.google.com/web/tools/chrome-devtools/network-performance/understanding-resource-timing)
8190

8291
### Smaller files
8392
Minification, Uglification and Dead Code Elimination all contribute to reduce the total size
84-
of your code to the smallest possible amount of bytes, which will result in a smaller
85-
transfer time.
93+
of your code to the smallest possible amount of bytes, which results in a smaller transfer time.
8694

8795
Tree shaking also reduces the total size but does so by removing whole exports from modules.
8896
It was popularized by [Rollup](http://rollupjs.org/) and you can read more about it in
@@ -91,15 +99,19 @@ a#overview
9199
### Template compilation
92100
AoT compilation reduces render time by pre-compiling Angular templates that otherwise would be
93101
compiled at runtime.
94-
It also reduces payload size since the Angular compiler itself is no longer needed, and nor are
95-
directives that are never used in templates. This allows Tree-Shaking to further remove exports.
102+
It also reduces payload size since the compiled app does not depend on the Angular compiler,
103+
nor on declared directives that are never used in templates.
104+
This allows Tree-Shaking to further remove exports.
96105

97106
You can read more about AoT Compilation in our [dedicated cookbook chapter](aot-compiler.html),
98-
where you'll also find instructions on how to use Rollup to do all the optimizations shown here.
107+
where you'll also find instructions on how to use Rollup to perform all the optimizations shown here.
108+
99109
Another great choice is [Webpack 2](https://webpack.js.org/) together with the
100110
[Angular Ahead-of-Time Webpack Plugin](https://github.com/angular/angular-cli/tree/master/packages/%40ngtools/webpack).
111+
Webpack is an easy to customize, high performance bundler, and the official AoT Webpack plugin
112+
makes it easier than ever to use AoT and lazy-loading.
101113

102-
You can use any build system you like however, the only important thing is to optimize your build.
114+
You can use any build system you like; the only important thing is to optimize your build.
103115
Whatever build system you choose make sure to automate it so that you can make a production
104116
build in a single step.
105117

@@ -112,26 +124,26 @@ a#overview
112124
There is an important configuration item in the Angular Router that needs to be adjusted for
113125
different environments:
114126
[the `base` tags `href` property](https://angular.io/docs/ts/latest/guide/router.html#!#base-href).
115-
This property tells the router how what the app root URL is so that the router can match routes.
127+
This property tells the router what the app root URL is so that the router can match routes.
116128

117129
On your development server, your app is most likely served at the root: `http://localhost:3000/`.
118130
Here you use `<base href="/">`, since `/` is the root of your app.
119131

120-
But depending on the server setup that you use, it can also be served in a subfolder like
132+
But depending on the server setup that you use, the app can be served from a subfolder like
121133
`http://localhost:3000/myapp/` or `http://www.mysite.com/myapp/`, where `/myapp/` is the subfolder.
122134
In this case you should use `<base href="/myapp/">`, since `/myapp/` is the root of your app and
123135
not `/`.
124136

125-
When your `base` tag is misconfigured your browser console will show several console, from
126-
missing files on wrong paths to router errors about missing routes.
137+
When your `base` tag is misconfigured your browser console will show several errors in the console,
138+
from missing files on wrong paths to router errors about missing routes.
127139

128140
### enableProdMode
129141

130142
You can also configure your Angular app to start on
131143
[production mode](https://angular.io/docs/ts/latest/api/core/index/enableProdMode-function.html),
132144
which will make it faster by disabling development specific checks.
133145

134-
Angular apps default do development move, as you can see by the following message on the browser
146+
Angular apps default to development mode, as you can see by the following message on the browser
135147
console:
136148

137149
code-example(format="nocode").
@@ -159,13 +171,13 @@ code-example().
159171
it to be imported directly instead of being imported via the Router.
160172

161173
It's important to note that your bundling configuration must take lazy loading into consideration.
162-
Since there is no ES6 import for that module, normal bundlers don't know that they should also
163-
separately bundle to module listed in the router config.
164-
You have to manually create additional bundles for each lazy loaded route.
174+
Since there is no ES6 import for that module, bundlers don't know that they should also
175+
separately bundle modules listed in the router config.
176+
You have to manually create additional bundles for each lazy loaded Angular Module.
165177

166178
If you are using Webpack, the
167179
[Angular Ahead-of-Time Webpack Plugin](https://github.com/angular/angular-cli/tree/master/packages/%40ngtools/webpack)
168-
will automatically recognize lazy routes.
180+
will automatically recognize lazy loaded NgModules.
169181

170182

171183
.l-main-section
@@ -174,12 +186,11 @@ code-example().
174186

175187
Angular apps are
176188
[Single Page Applications](https://en.wikipedia.org/wiki/Single-page_application) (SPAs),
177-
which makes them the perfect candidates to be served by simple static HTML server.
189+
which makes them the perfect candidates to be served by a simple static HTML server.
178190
No preprocessors required!
179191

180192
There is only one configuration item required of a server hosting an Angular app:
181-
it needs to be able to fallback to `index.html` when being asked for a file the server
182-
does not have.
193+
it needs to fallback to `index.html` when being asked for a file the server does not have.
183194

184195
### Why fallback to `index.html`?
185196

@@ -196,8 +207,8 @@ code-example().
196207
Then you click the link for `admin/` and the your address bar will change
197208
to `www.my-awesome-app.com/admin/` and you're taken to the admin page.
198209

199-
But if you don't have fallback to `index.html` configured and refresh the page, you will
200-
get a `404 - Not Found` page!
210+
If you then refresh the page, you will get a `404 - Not Found` page unless you have the fallback
211+
to `index.html` configured!
201212
Which doesn't make a lot of sense since you just saw that the admin page was there.
202213

203214
When you first clicked the link to `admin/` there was no server request for
@@ -210,17 +221,17 @@ code-example().
210221

211222
That is why the server needs to be configured to fallback to `index.html`.
212223
When a user asks the server for any route (that isn't a file), you want the server to *always*
213-
return default page that boots up Angular.
214-
After Angular is loaded and bootstrapped the router will look at the address bar and take
215-
the user where he needs to go.
224+
return the default page that boots up Angular.
225+
After Angular is loaded and bootstrapped the router looks at the address bar and takes
226+
the user to the appropriate route.
216227

217228
### Fallback configuration examples
218229

219230
Different servers are configured in different ways so there is no single configuration that
220231
works everywhere.
221232

222233
Following are configurations for some of the most popular servers.
223-
The list is by no means exhausting, but should provide you with a good starting point.
234+
The list is by no means exhaustive, but should provide you with a good starting point.
224235

225236
#### Development servers
226237

@@ -310,7 +321,7 @@ code-example(format=".").
310321
These are not due to the SPA application itself but rather due to the configuration of APIs with
311322
which the SPA communicates.
312323

313-
These APIs need to send the `Access-Control-Allow-Origin: *` header on their HTTP responses,
314-
otherwise the SPA will not be able to call them.
324+
If these APIs are on different domains, they need to send the `Access-Control-Allow-Origin: *`
325+
header on their HTTP responses otherwise the SPA will not be able to call them.
315326
You can read more about how to enable CORS for specific servers in
316327
[enable-cors.org](http://enable-cors.org/server.html)

0 commit comments

Comments
 (0)