7 Peaks Software Angular Meetup July 2019.
How We Build NG-MY Websites: Performance, SEO, CI, CD by Jecelyn Yeen – Developer expert at Google Calendar. Google Developer Expert.
Angular 8 is the newest version on the block, and comes with the effective CLI API, helping make developers experience better. Offering differential loading support for modern browser, and faster loading, and also includes Ivy renderer tree-shaking for a smaller website.
See all the event details here -> http://7peakssoftware.com/angular-meetup-2019/
Stay tuned to get information about 7 Peaks Software’s next Angular meetup at https://7peakssoftware.com/events/
15. <title>July 06-07 | NG-MY 2019</title>
<meta name="description" content="NG-MY 2019...">
<meta property="og:url" content="https://2019.ng-my.org/" />
<meta property="og:description" content="NG-MY 2019...">
<meta property="og:type" content="website" />
<meta property="og:title" content="..." />
<meta property="og:image" content="img.png" />
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="img.png">
Title tag & Meta tags are
essential for SEO
16. export class PageService {
}
Utilize the built-in
Title & Meta Service
Set page title
Update meta tag
Inject title & meta services
constructor(private title: Title, private meta: Meta) {}
setPageMeta(title: string, metaDesc: string, metaImg: string) {
this.title.setTitle(title);
this.meta.updateTag({ property: 'og:title', content: title });
this.meta.updateTag({ name: 'description', content: metaDesc });
this.meta.updateTag({ name: 'twitter:image', content: metaImg });
...
}
22. SEO Problem in SPA
<html>
<head>
<script src="bundle.js">
</head>
...
</html>
Server sends HTML to Client
(No meta tags)
<html>
<head>
<title>home</title>
<meta ...>
<script src="bundle.js">
</head>
...
</html>
Client executes JS and add
title & meta tags (too late!)
Most
crawlers
only
understand
this. :(
24. Solution: Prerendering during build time
ng build --prod
Generate index.html, js,
css, etc files
Open browser
Browse & Save each
route as .html
Deploy all files to
server
Generate static html pages =
Prerendering
25. Solution: Prerendering during build time
ng build --prod
Generate index.html, js,
css, etc files
Open browser
Browse & Save each
route as .html
Deploy all files to
server
Automate Prerendering
using Puppeteer
27. Solution: Prerendering during build time
ng build --prod
Generate index.html, js,
css, etc files
Program Puppeteer
Browse & Save each
route as .html
Deploy all files to
server
Extend Angular CLI Webpack
to prerender
28. Extend Angular CLI Webpack to handle Prerendering
npm install -D
@angular-builders/custom-webpack
npm install -D
prerender-spa-plugin
Extend Angular CLI Webpack
Webpack Plugins to
Prerender with Puppeteer
https://github.com/meltedspark/angular-builders
https://github.com/chrisvfritz/prerender-spa-plugin
29. const PrerenderSPAPlugin = require('prerender-spa-plugin');
const routes = ['/food', '/team', '/speakers', ...]
module.exports = {
plugins: [
new PrerenderSPAPlugin({
staticDir: 'dist/site/2019',
routes
})]
}
extra-webpack.config.js
Update angular.json
to use this custom webpack file
30. Sitemap is still necessary
https://support.google.com/webmasters/answer/156184?hl=en
31. Solution: Generate Sitemap Automatically
ng build --prod
Generate index.html, js,
css, etc files
Deploy all files to
server
Generate sitemap.xml
Extend Angular CLI Webpack
to do so
32. Extend Angular CLI for Sitemap Generation
npm install -D
create-file-webpack
https://github.com/Appius/create-file-webpack
Webpack plugin to
create file (any format)
40. Flow
Create PR PR Approved
Merge to
Master Branch
Trigger Build Trigger Deployment
Complete feature development
Automate with Travis CI
(free for public project)
58. Serve WebP and
support browsers
<picture>
<source srcset="teh-tarik.webp" type="image/webp">
<img src="teh-tarik.png">
</picture>
Image container If browser
supports WebP
Else PNG it is
69. Flash of Unstyled
Text (FOUT)
@font-face {
font-family: Source Sans Pro', sans-serif;
src: url('...') format('woff');
font-display: swap;
} Display unstyled text until
font loaded
.5s improvement in
“Visual Complete” on 3G
82. Defer Google Tag Manager
<script defer
src="https://www.googletagmanager.com/gtag/js?id=xxx">
</script>
<script>
...
</script>
Defer it
Reduction of
domComplete time
88. Performance Optimization we get for FREE!
➔ Minification & Uglify (CLI)
➔ Ahead of Time Compilation (CLI)
➔ GZIP (Firebase)
➔ Differential Loading (CLI)