{ "id": "guide/app-shell", "title": "App shell", "contents": "\n\n\n
\n mode_edit\n
\n\n\n
\n

App shelllink

\n

App shell is a way to render a portion of your application via a route at build time.\nIt 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.

\n

This gives users a meaningful first paint of your application that appears quickly because the browser can simply render the HTML and CSS without the need to initialize any JavaScript.

\n

Learn more in The App Shell Model.

\n

Step 1: Prepare the applicationlink

\n

You can do this with the following CLI command:\n\nng new my-app --routing\n

\n

For an existing application, you have to manually add the RouterModule and defining a <router-outlet> within your application.

\n

Step 2: Create the app shelllink

\n

Use the CLI to automatically create the app shell.

\n\nng generate app-shell\n\n\n

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.

\n\n\"server\": {\n \"builder\": \"@angular-devkit/build-angular:server\",\n \"defaultConfiguration\": \"production\",\n \"options\": {\n \"outputPath\": \"dist/my-app/server\",\n \"main\": \"src/main.server.ts\",\n \"tsConfig\": \"tsconfig.server.json\"\n },\n \"configurations\": {\n \"development\": {\n \"outputHashing\": \"none\",\n },\n \"production\": {\n \"outputHashing\": \"media\",\n \"fileReplacements\": [\n {\n \"replace\": \"src/environments/environment.ts\",\n \"with\": \"src/environments/environment.prod.ts\"\n }\n ],\n \"sourceMap\": false,\n \"optimization\": true\n }\n }\n},\n\"app-shell\": {\n \"builder\": \"@angular-devkit/build-angular:app-shell\",\n \"defaultConfiguration\": \"production\",\n \"options\": {\n \"route\": \"shell\"\n },\n \"configurations\": {\n \"development\": {\n \"browserTarget\": \"my-app:build:development\",\n \"serverTarget\": \"my-app:server:development\",\n },\n \"production\": {\n \"browserTarget\": \"my-app:build:production\",\n \"serverTarget\": \"my-app:server:production\"\n }\n }\n}\n\n

Step 3: Verify the app is built with the shell contentlink

\n

Use the CLI to build the app-shell target.

\n\nng run my-app:app-shell:development\n\n

Or to use the production configuration.

\n\nng run my-app:app-shell:production\n\n

To verify the build output, open dist/my-app/browser/index.html. Look for default text app-shell works! to show that the app shell route was rendered as part of the output.

\n\n \n
\n\n\n" }