SlideShare a Scribd company logo
Building a dynamic SPA
a journey with @filipbech
@IMPACTdigitaldk
Filip
@filipbech
!
#weAreHiring #denmark
https://www.facebook.com/groups/ngAarhus/
https://developers.google.com/experts/people/filip-bruun-bech-larsen
…enough about me
let’s use Angular for dynamic content
Building a dynamic SPA
a journey with @filipbech
@IMPACTdigitaldk
or “How to use Angular
with your cms”
Let’s do like angular 1
NOPE
need to bootstrap a component
Building a dynamic SPA website with Angular
…but we have no root app?
• multiple entrypoints
Bootstrapping multiple
applications
• its a little harder to maintain state between applications
(but possible)
• the cms now needs to know what components are
angular-components, so they can all be bootstrapped.
(and their DOM-nodes if multiple of the same
component)
Building a dynamic SPA website with Angular
Initial data
• We need to feed data (settings, initial data) into some of
the components (from the cms), and put content inside
them.
Building a dynamic SPA website with Angular
NOPE
Because
• Root-components cannot have inputs
• Root-components cannot use content-projection
(transclusion)
https://github.com/angular/angular/issues/1858
How about a <body>-
component then?
Building a dynamic SPA website with Angular
Eeeewwwww
• even though it works - it feels terrible and wrong!
• and we need the parser at runtime
• so no AOT and bad perf
We need a SPA
Single Page Application
• so we can also share state between routes
• animate route-changes
• and much more…
Demo-time
to heighten the suspense…
Building a dynamic SPA website with Angular
It starts with a router
…thats not very dynamic
We have too many routes with
no patterns
• “/“ is a frontpage
• “/om/os” is a content-page
• “/mejeri“ is a category-page
• “/mejeri/ost“ is a sub-category-page
• “/ost-i-skiver-mild-13-cheasy-200-g” is a product-page
So I talked to the Angular team…
…let the CMS
output route-config
Two issues with that approach
• Need to build and invalidate the bundle’s cache every
time an editor makes a change
• Users get stuck on the route-config they get at first load
One route to rule them all
Building a dynamic SPA website with Angular
**-route + generic
PageComponent
Get the data in a resolve
PageResolve is just a class with resolve(route)-method on it
In angular 1.x we could use templateFactory and
select a template based on the api-response
But we cannot do that in Angular 2+, because 

there is no template-parser at runtime
All possible
PageComponents with
individual *ngIf’s
Building a dynamic SPA website with Angular
Eeeewwwww
Even though all the *ngIfs in the template are AOT
compiled into something more acceptable…
It still seems wrong to have it in the template!
but (for now) it works…
until you navigate around

(nothing happens)
you’re not changing the route
just its options
(so: no new resolve, no new ngOnInit)
Refactoring
• Listen for route-changes and handle resolving data
manually
Building a dynamic SPA website with Angular
The problem cascades
• When we go from one product-detail-page to another
product-detail-page…
• Refactor init-logic into ngOnChanges
Then came rc4
ComponentFactoryResolver adds beauty
and power to generic components…
The theory
Building a dynamic SPA website with Angular
What components
should be available?
Building a dynamic SPA website with Angular
We need a routeChange
for animations
and it would feel a lot better too
Custom RouterReuseStrategy
Building a dynamic SPA website with Angular
Building a dynamic SPA website with Angular
What about Rich-text
content from the CMS?
Building a dynamic SPA website with Angular
Building a dynamic SPA website with Angular
ng-bind-html
Building a dynamic SPA website with Angular
Perfect, except for links
the router doesn’t “hijack”
a[href]-clicks like uiRouter
enter the [href] directive
NOPE
@Hostlistener =>
router.go()
* in reality it’s a little more complicated
Sweeeet
all we ever wanted
Without all the ugly
Flexibility
real routes => getting data in resolve + animations
Rich Text
Same approach for the
dynamic content spots
* we add another directive so we can repeat via *ngForOf
AOT
#justWorks
Building a dynamic SPA website with Angular
Add PageComponents to
ngModule entryComponents
Faster and lighter
Initial parse goes from 450ms to 250ms
Without AOT
With AOT
Server Side Rendering
SEO, social previews and 

faster perceived load-times
Angular Universal is so hot right now…(in core)
Hard to wrap your head
around universal
The idea
• server.module and a client.module
• they both import the app.module
• server and client module then replaces the
dependencies that are different with appropriate
environment-versions (eg. xhr or node-fetch, DOM or
virtual-dom)
Can’t touch this (the DOM)
(no direct window, querySelector, localstorage)
Building a dynamic SPA website with Angular
Building a dynamic SPA website with Angular
Maintaining state
we want to maintain state, so we don’t re-do all fetches
and calculations when the client boots up
StateTransfer Service
holds data
+ hooks for dehydrate/rehydrate via json
* idea credit to the universal creators…
Building a dynamic SPA website with Angular
Building a dynamic SPA website with Angular
Building a dynamic SPA website with Angular
Building a dynamic SPA website with Angular
CACHING OF SSR
can’t work with personalisation
3 strategies
at Launch
at user
interaction
just don’t
enter no-ssr directive
Building a dynamic SPA website with Angular
Building a dynamic SPA website with Angular
We made it to nirvana
Thank you, this was:
“building a dynamic SPA with Angular”
I’m @filipbech
code: https://github.com/filipbech/ng-dynamic-spa
@IMPACTdigitaldk
Building a dynamic SPA website with Angular

More Related Content

PDF
Angular ❤️CMS
PDF
Angular ❤️ CMS from #AngularUp
PPTX
Dynamic content with Angular
PPTX
European Collaboration Summit - SharePoint Framework Angular & Azure Functions
PDF
BP101: A Modernized Workflow w/ Domino/XPages
PDF
Introduction To Single Page Application
PPTX
SharePoint Saturday Twin Cities - SharePoint Framework, Angular & Azure Funct...
PDF
Client Vs. Server Rendering
Angular ❤️CMS
Angular ❤️ CMS from #AngularUp
Dynamic content with Angular
European Collaboration Summit - SharePoint Framework Angular & Azure Functions
BP101: A Modernized Workflow w/ Domino/XPages
Introduction To Single Page Application
SharePoint Saturday Twin Cities - SharePoint Framework, Angular & Azure Funct...
Client Vs. Server Rendering

What's hot (20)

PPTX
Lightweight webdev
PDF
Isomorphic web application
PPTX
SharePoint Saturday Vancouver - SharePoint Framework, Angular and Azure Funct...
PPTX
SharePoint Fest DC - SharePoint Framework, Angular and Azure Functions
PDF
React server side rendering performance
PPTX
Rise of the responsive single page application
PPTX
North American Collaboration Summit 2018 - SharePoint Framework, Angular & Az...
PDF
Angular 2 vs React
PPTX
Angular.js in XPages
PDF
Getting Started with the Angular 2 CLI
PDF
Server rendering-talk
PDF
Contentful with Netgen Layouts workshop
PDF
Website building exercise
PPTX
Advanced AngularJS Tips and Tricks
PDF
Developing webapp using Polymer : is it ready for production? or not?
PDF
The Dark Side of Single Page Applications
PDF
Introduction to React Native
PDF
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
PPTX
Isomorphic JavaScript – future of the web
PDF
RailsAdmin - Overview and Best practices
Lightweight webdev
Isomorphic web application
SharePoint Saturday Vancouver - SharePoint Framework, Angular and Azure Funct...
SharePoint Fest DC - SharePoint Framework, Angular and Azure Functions
React server side rendering performance
Rise of the responsive single page application
North American Collaboration Summit 2018 - SharePoint Framework, Angular & Az...
Angular 2 vs React
Angular.js in XPages
Getting Started with the Angular 2 CLI
Server rendering-talk
Contentful with Netgen Layouts workshop
Website building exercise
Advanced AngularJS Tips and Tricks
Developing webapp using Polymer : is it ready for production? or not?
The Dark Side of Single Page Applications
Introduction to React Native
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
Isomorphic JavaScript – future of the web
RailsAdmin - Overview and Best practices
Ad

Similar to Building a dynamic SPA website with Angular (20)

PDF
Whats next in templating
PDF
The future of templating and frameworks
PDF
Aurelia intro
PDF
Whats next in templating
PPTX
SharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure Functions
PPTX
Angular js workshop
PPTX
SharePoint Saturday Utah 2018 - SharePoint Framework, Angular and Azure Funct...
PDF
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
PDF
Angular - Chapter 3 - Components
PDF
Integrating Social Apps with Content Driven Sites using Apache Rave and Sprin...
PPTX
SharePoint Framework, Angular and Azure Functions
PPTX
Angular 6 Training with project in hyderabad india
PPTX
Expo Router V2
PPTX
European SharePoint Conference 2017 - SharePoint Framework, Angular & Azure F...
PDF
Implement lazy loading in your existing angular application (get a faster, be...
PDF
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
PPTX
SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...
PPTX
Umbraco Cape Town Meetup Presentation
PPTX
Web worker in your angular application
PDF
Step by Step Guide on Lazy Loading in Angular 11
Whats next in templating
The future of templating and frameworks
Aurelia intro
Whats next in templating
SharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure Functions
Angular js workshop
SharePoint Saturday Utah 2018 - SharePoint Framework, Angular and Azure Funct...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
Angular - Chapter 3 - Components
Integrating Social Apps with Content Driven Sites using Apache Rave and Sprin...
SharePoint Framework, Angular and Azure Functions
Angular 6 Training with project in hyderabad india
Expo Router V2
European SharePoint Conference 2017 - SharePoint Framework, Angular & Azure F...
Implement lazy loading in your existing angular application (get a faster, be...
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...
Umbraco Cape Town Meetup Presentation
Web worker in your angular application
Step by Step Guide on Lazy Loading in Angular 11
Ad

More from Filip Bruun Bech-Larsen (20)

PDF
Webcomponents from 0-100 - with Google's Lit
PDF
Webcomponents are your frameworks best friend
PDF
Content as a Service with Umbraco Headless
PDF
Frameworks and webcomponents
PDF
Whats next in clientside templating
PDF
Whats next in clientside templating
PDF
Future of the Web
PDF
Diversity at impact
PDF
The Future of the web
PDF
Frontend development of the (current) future
PDF
Commerce and the browser in 2017
PPTX
Frontend State of the union
PPTX
AngularJS best practices
PPTX
Frontend development of the (current) future
PPTX
Observables - the why, what & how
PPTX
Angular2 workshop
PPTX
Progressive Web Apps og Payment Request
PPTX
Spangulumbraco
PPTX
Web development post io2016
PPTX
Observables in angular2
Webcomponents from 0-100 - with Google's Lit
Webcomponents are your frameworks best friend
Content as a Service with Umbraco Headless
Frameworks and webcomponents
Whats next in clientside templating
Whats next in clientside templating
Future of the Web
Diversity at impact
The Future of the web
Frontend development of the (current) future
Commerce and the browser in 2017
Frontend State of the union
AngularJS best practices
Frontend development of the (current) future
Observables - the why, what & how
Angular2 workshop
Progressive Web Apps og Payment Request
Spangulumbraco
Web development post io2016
Observables in angular2

Recently uploaded (20)

PDF
A comparative analysis of optical character recognition models for extracting...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Machine learning based COVID-19 study performance prediction
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPT
Teaching material agriculture food technology
PDF
Empathic Computing: Creating Shared Understanding
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
A comparative analysis of optical character recognition models for extracting...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Unlocking AI with Model Context Protocol (MCP)
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Reach Out and Touch Someone: Haptics and Empathic Computing
Machine learning based COVID-19 study performance prediction
MIND Revenue Release Quarter 2 2025 Press Release
20250228 LYD VKU AI Blended-Learning.pptx
MYSQL Presentation for SQL database connectivity
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Spectroscopy.pptx food analysis technology
Digital-Transformation-Roadmap-for-Companies.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Assigned Numbers - 2025 - Bluetooth® Document
Teaching material agriculture food technology
Empathic Computing: Creating Shared Understanding
“AI and Expert System Decision Support & Business Intelligence Systems”

Building a dynamic SPA website with Angular