2019-02-07 13:41:10 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# App shell
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-04-09 05:33:21 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Application shell is a way to render a portion of your application using a route at build time.
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 13:41:10 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								It can improve the user experience by quickly launching a static rendered page (a skeleton common to all pages) while the browser downloads the full client version and switches to it automatically after the code loads.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-04-09 05:33:21 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This gives users a meaningful first paint of your application that appears quickly because the browser can render the HTML and CSS without the need to initialize any JavaScript.
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 13:41:10 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Learn more in [The App Shell Model ](https://developers.google.com/web/fundamentals/architecture/app-shell ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Step 1: Prepare the application
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								You can do this with the following CLI command:
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 23:02:36 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< code-example  language = "bash" >  
						 
					
						
							
								
									
										
										
										
											2019-02-07 13:41:10 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								ng new my-app --routing
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / code-example >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								For an existing application, you have to manually add the `RouterModule`  and defining a `<router-outlet>`  within your application.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Step 2: Create the app shell
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-04-09 05:33:21 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Use the CLI to automatically create the application shell.
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 13:41:10 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 23:02:36 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< code-example  language = "bash" >  
						 
					
						
							
								
									
										
										
										
											2019-10-08 19:31:44 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ng generate app-shell
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 13:41:10 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< / code-example >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-06 12:57:59 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								For more information about this command see [App shell command ](cli/generate#app-shell-command ). 
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 13:41:10 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								After running this command you will notice that the `angular.json`  configuration file has been updated to add two new targets, with a few other changes.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 23:02:36 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< code-example  language = "json" >  
						 
					
						
							
								
									
										
										
										
											2019-02-07 13:41:10 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								"server": {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "builder": "@angular -devkit/build-angular:server",
							 
						 
					
						
							
								
									
										
										
										
											2021-03-12 08:14:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  "defaultConfiguration": "production",
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 13:41:10 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  "options": {
							 
						 
					
						
							
								
									
										
										
										
											2020-12-19 18:39:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    "outputPath": "dist/my-app/server",
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 13:41:10 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    "main": "src/main.server.ts",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "tsConfig": "tsconfig.server.json"
							 
						 
					
						
							
								
									
										
										
										
											2020-12-19 18:39:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  },
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "configurations": {
							 
						 
					
						
							
								
									
										
										
										
											2021-03-12 08:14:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    "development": {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      "outputHashing": "none",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    },
							 
						 
					
						
							
								
									
										
										
										
											2020-12-19 18:39:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    "production": {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      "outputHashing": "media",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      "fileReplacements": [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          "replace": "src/environments/environment.ts",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          "with": "src/environments/environment.prod.ts"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      ],
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      "sourceMap": false,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      "optimization": true
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 13:41:10 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								},
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"app-shell": {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "builder": "@angular -devkit/build-angular:app-shell",
							 
						 
					
						
							
								
									
										
										
										
											2021-03-12 08:14:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  "defaultConfiguration": "production",
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 13:41:10 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  "options": {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "route": "shell"
							 
						 
					
						
							
								
									
										
										
										
											2019-09-04 15:52:57 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  },
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  "configurations": {
							 
						 
					
						
							
								
									
										
										
										
											2021-03-12 08:14:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    "development": {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      "browserTarget": "my-app:build:development",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      "serverTarget": "my-app:server:development",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    },
							 
						 
					
						
							
								
									
										
										
										
											2019-09-04 15:52:57 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    "production": {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      "browserTarget": "my-app:build:production",
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      "serverTarget": "my-app:server:production"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 13:41:10 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / code-example >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Step 3: Verify the app is built with the shell content
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Use the CLI to build the `app-shell`  target.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 23:02:36 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< code-example  language = "bash" >  
						 
					
						
							
								
									
										
										
										
											2021-03-12 08:14:30 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								ng run my-app:app-shell:development
							 
						 
					
						
							
								
									
										
										
										
											2019-02-07 13:41:10 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< / code-example >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-09-04 15:52:57 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Or to use the production configuration.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< code-example  language = "bash" >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								ng run my-app:app-shell:production
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / code-example >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-04-09 05:33:21 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								To verify the build output, open `dist/my-app/browser/index.html` . Look for default text `app-shell works!`  to show that the application shell route was rendered as part of the output.