The App shell pattern is a way to render a portion of your application using a route at build time. 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.
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.
-
Prepare the application
Do this with the following Angular CLI command:
ng new my-app --routing
For an existing application, you have to manually add the
Router
and defining a<router-outlet>
within your application. -
Create the application shell
Use the Angular CLI to automatically create the application shell.
ng generate app-shell
For more information about this command, see App shell command.
The command updates the application code and adds extra files to the project structure.
srcâââ appâ âââ app.config.server.ts # server application configurationâ âââ app-shell # app-shell componentâ âââ app-shell.component.htmlâ âââ app-shell.component.scssâ âââ app-shell.component.spec.tsâ âââ app-shell.component.tsâââ main.server.ts # main server application bootstrapping
ng build --configuration=development
Or to use the production configuration.
ng build
To verify the build output, open
dist/my-app/browser/index.html
. Look for default textapp-shell works!
to show that the application shell route was rendered as part of the output.