insights covering & fast integration.
Ah, another Angular 9 feature everyone knows about π€«
Angular Workshop
Angular Minsk
Participant:
Angular Belarus
You'll know this, but let me remind...
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Angular NYC conf !</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<div class="center logo">
<img width="128" src="assets/images/logos/logo-full.png">
</div>
<app-root></app-root>
</body>
</html>
./src/index.html
Request /
Request scripts
Execute scripts
β
~1400ms
Request /
Run app on server
Request scripts
NOT INTERACTABLE
β
~600ms
Request /
Precompile Angular html
for every route
Request scripts
NOT INTERACTABLE
β
Build time:
~30ms
- HTML and CSS loads
- Site is visible
these not interactable yet
~1400ms
~600ms
~30ms
Pure Angular
Universal
Pre-render
| pros | cons | |
|---|---|---|
|
Dynamic SSR |
suitable for apps with dynamic content |
if not cached β server generates response additional server for serving SSR content needed |
|
Static Pre-Rendering |
easy to CDN server doesn't have to generate the files |
not suitable for apps with dynamic content (not really) |
β
π’
json/markdown files as page content
document / window / navigator
3rd party libs which access the DOM
β
ng add @nguniversal/express-engine
const routes: Routes = [
{
path: 'one',
component: PageOneComponent
},
{
path: 'two',
component: PageTwoComponent
}
];
@NgModule({
imports: [RouterModule.forRoot(routes, {
initialNavigation: 'enabled'
})],
exports: [RouterModule]
})
export class AppRoutingModule { }<ul>
<li><a routerLink="/">Home</a></li>
<li><a routerLink="/one">Page One</a></li>
<li><a routerLink="/two">Page Two</a></li>
</ul>
<router-outlet></router-outlet> "prerender": {
"builder": "@nguniversal/builders:prerender",
"options": {
"browserTarget": "static-app:build:production",
"serverTarget": "static-app:server:production",
"routes": [ // Handling dynamic routes
"/",
"/one",
"/two",
"/products/1234",
"/products/05919251"
]
}guess-parser statically analyze Angular application to discover how the routes from the analytics source map to JavaScript bundles.
Transfer state Β π
Do Universal for Dynamic pages Β π‘
Setup all necessary pages π
β’ guess-parser is not an everything-parser
Initial content for SEO and Social Media π
β’ blog, E-commerce, news website, any content website
Increase perceived perfomance πΒ
β’ contentful - meaningful
π Doesn't know about dynamic routes
π Angular Bundle downloading
π€― Juniors will be shocked
Β π€ Not for internal apps