SlideShare une entreprise Scribd logo
1  sur  99
Télécharger pour lire hors ligne
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
…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)
Initial data
• We need to feed data (settings, initial data) into some of
the components (from the cms), and put content inside
them.
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?
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…
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
**-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
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
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
What components
should be available?
We need a routeChange
for animations
and it would feel a lot better too
Custom RouterReuseStrategy
What about Rich-text
content from the CMS?
ng-bind-html
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
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)
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…
CACHING OF SSR
can’t work with personalisation
3 strategies
at Launch
at user
interaction
just don’t
enter no-ssr directive
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

Contenu connexe

Tendances

Open API Strategy, by Sensedia
Open API Strategy, by SensediaOpen API Strategy, by Sensedia
Open API Strategy, by Sensedia
Sensedia
 

Tendances (20)

Scaling Apache Pulsar to 10 PB/day
Scaling Apache Pulsar to 10 PB/dayScaling Apache Pulsar to 10 PB/day
Scaling Apache Pulsar to 10 PB/day
 
Microservices with Apache Camel
Microservices with Apache CamelMicroservices with Apache Camel
Microservices with Apache Camel
 
Apache Camel with Spring boot
Apache Camel with Spring bootApache Camel with Spring boot
Apache Camel with Spring boot
 
API
APIAPI
API
 
Hexagonal architecture for java applications
Hexagonal architecture for java applicationsHexagonal architecture for java applications
Hexagonal architecture for java applications
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Spring RabbitMQ
Spring RabbitMQSpring RabbitMQ
Spring RabbitMQ
 
Open API Strategy, by Sensedia
Open API Strategy, by SensediaOpen API Strategy, by Sensedia
Open API Strategy, by Sensedia
 
Apache BookKeeper State Store: A Durable Key-Value Store - Pulsar Summit NA 2021
Apache BookKeeper State Store: A Durable Key-Value Store - Pulsar Summit NA 2021Apache BookKeeper State Store: A Durable Key-Value Store - Pulsar Summit NA 2021
Apache BookKeeper State Store: A Durable Key-Value Store - Pulsar Summit NA 2021
 
Overview of Message Queues
Overview of Message QueuesOverview of Message Queues
Overview of Message Queues
 
Ldap introduce
Ldap introduceLdap introduce
Ldap introduce
 
Amazon Web Service Sales Role Play - Case Study
Amazon Web Service Sales Role Play - Case StudyAmazon Web Service Sales Role Play - Case Study
Amazon Web Service Sales Role Play - Case Study
 
Getting Started with Apache Spark on Kubernetes
Getting Started with Apache Spark on KubernetesGetting Started with Apache Spark on Kubernetes
Getting Started with Apache Spark on Kubernetes
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
 
Spring JMS
Spring JMSSpring JMS
Spring JMS
 
Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
 
Migrating Data and Databases to Azure
Migrating Data and Databases to AzureMigrating Data and Databases to Azure
Migrating Data and Databases to Azure
 
Declarative Clients in Spring
Declarative Clients in SpringDeclarative Clients in Spring
Declarative Clients in Spring
 
Camel Day Italy 2021 - What's new in Camel 3
Camel Day Italy 2021 - What's new in Camel 3Camel Day Italy 2021 - What's new in Camel 3
Camel Day Italy 2021 - What's new in Camel 3
 
Angular Seminar-js
Angular Seminar-jsAngular Seminar-js
Angular Seminar-js
 

Similaire à Building a dynamic SPA website with Angular

European Collaboration Summit - SharePoint Framework Angular & Azure Functions
European Collaboration Summit - SharePoint Framework Angular & Azure FunctionsEuropean Collaboration Summit - SharePoint Framework Angular & Azure Functions
European Collaboration Summit - SharePoint Framework Angular & Azure Functions
Sébastien Levert
 
SharePoint Fest DC - SharePoint Framework, Angular and Azure Functions
SharePoint Fest DC - SharePoint Framework, Angular and Azure FunctionsSharePoint Fest DC - SharePoint Framework, Angular and Azure Functions
SharePoint Fest DC - SharePoint Framework, Angular and Azure Functions
Sébastien Levert
 
SharePoint Saturday Vancouver - SharePoint Framework, Angular and Azure Funct...
SharePoint Saturday Vancouver - SharePoint Framework, Angular and Azure Funct...SharePoint Saturday Vancouver - SharePoint Framework, Angular and Azure Funct...
SharePoint Saturday Vancouver - SharePoint Framework, Angular and Azure Funct...
Sébastien Levert
 
SharePoint Saturday Twin Cities - SharePoint Framework, Angular & Azure Funct...
SharePoint Saturday Twin Cities - SharePoint Framework, Angular & Azure Funct...SharePoint Saturday Twin Cities - SharePoint Framework, Angular & Azure Funct...
SharePoint Saturday Twin Cities - SharePoint Framework, Angular & Azure Funct...
Sébastien Levert
 
SharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure FunctionsSharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure Functions
Sébastien Levert
 
SharePoint Saturday Utah 2018 - SharePoint Framework, Angular and Azure Funct...
SharePoint Saturday Utah 2018 - SharePoint Framework, Angular and Azure Funct...SharePoint Saturday Utah 2018 - SharePoint Framework, Angular and Azure Funct...
SharePoint Saturday Utah 2018 - SharePoint Framework, Angular and Azure Funct...
Sébastien Levert
 
SharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure FunctionsSharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure Functions
Sébastien Levert
 

Similaire à Building a dynamic SPA website with Angular (20)

Angular ❤️CMS
Angular ❤️CMSAngular ❤️CMS
Angular ❤️CMS
 
Angular ❤️ CMS from #AngularUp
Angular ❤️ CMS from #AngularUpAngular ❤️ CMS from #AngularUp
Angular ❤️ CMS from #AngularUp
 
Dynamic content with Angular
Dynamic content with AngularDynamic content with Angular
Dynamic content with Angular
 
European Collaboration Summit - SharePoint Framework Angular & Azure Functions
European Collaboration Summit - SharePoint Framework Angular & Azure FunctionsEuropean Collaboration Summit - SharePoint Framework Angular & Azure Functions
European Collaboration Summit - SharePoint Framework Angular & Azure Functions
 
Whats next in templating
Whats next in templatingWhats next in templating
Whats next in templating
 
The future of templating and frameworks
The future of templating and frameworksThe future of templating and frameworks
The future of templating and frameworks
 
SharePoint Fest DC - SharePoint Framework, Angular and Azure Functions
SharePoint Fest DC - SharePoint Framework, Angular and Azure FunctionsSharePoint Fest DC - SharePoint Framework, Angular and Azure Functions
SharePoint Fest DC - SharePoint Framework, Angular and Azure Functions
 
SharePoint Saturday Vancouver - SharePoint Framework, Angular and Azure Funct...
SharePoint Saturday Vancouver - SharePoint Framework, Angular and Azure Funct...SharePoint Saturday Vancouver - SharePoint Framework, Angular and Azure Funct...
SharePoint Saturday Vancouver - SharePoint Framework, Angular and Azure Funct...
 
Aurelia intro
Aurelia introAurelia intro
Aurelia intro
 
Whats next in templating
Whats next in templatingWhats next in templating
Whats next in templating
 
SharePoint Saturday Twin Cities - SharePoint Framework, Angular & Azure Funct...
SharePoint Saturday Twin Cities - SharePoint Framework, Angular & Azure Funct...SharePoint Saturday Twin Cities - SharePoint Framework, Angular & Azure Funct...
SharePoint Saturday Twin Cities - SharePoint Framework, Angular & Azure Funct...
 
SharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure FunctionsSharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Chicago 2017 - SharePoint Framework, Angular & Azure Functions
 
Angular js workshop
Angular js workshopAngular js workshop
Angular js workshop
 
SharePoint Saturday Utah 2018 - SharePoint Framework, Angular and Azure Funct...
SharePoint Saturday Utah 2018 - SharePoint Framework, Angular and Azure Funct...SharePoint Saturday Utah 2018 - SharePoint Framework, Angular and Azure Funct...
SharePoint Saturday Utah 2018 - SharePoint Framework, Angular and Azure Funct...
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
 
Integrating Social Apps with Content Driven Sites using Apache Rave and Sprin...
Integrating Social Apps with Content Driven Sites using Apache Rave and Sprin...Integrating Social Apps with Content Driven Sites using Apache Rave and Sprin...
Integrating Social Apps with Content Driven Sites using Apache Rave and Sprin...
 
SharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure FunctionsSharePoint Framework, Angular and Azure Functions
SharePoint Framework, Angular and Azure Functions
 
Angular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad indiaAngular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad india
 
Expo Router V2
Expo Router V2Expo Router V2
Expo Router V2
 

Plus de Filip Bruun Bech-Larsen

Plus de Filip Bruun Bech-Larsen (20)

Webcomponents from 0-100 - with Google's Lit
Webcomponents from 0-100 - with Google's LitWebcomponents from 0-100 - with Google's Lit
Webcomponents from 0-100 - with Google's Lit
 
Webcomponents are your frameworks best friend
Webcomponents are your frameworks best friendWebcomponents are your frameworks best friend
Webcomponents are your frameworks best friend
 
Content as a Service with Umbraco Headless
Content as a Service with Umbraco HeadlessContent as a Service with Umbraco Headless
Content as a Service with Umbraco Headless
 
Frameworks and webcomponents
Frameworks and webcomponentsFrameworks and webcomponents
Frameworks and webcomponents
 
Whats next in clientside templating
Whats next in clientside templatingWhats next in clientside templating
Whats next in clientside templating
 
Whats next in clientside templating
Whats next in clientside templatingWhats next in clientside templating
Whats next in clientside templating
 
Future of the Web
Future of the WebFuture of the Web
Future of the Web
 
Diversity at impact
Diversity at impactDiversity at impact
Diversity at impact
 
The Future of the web
The Future of the webThe Future of the web
The Future of the web
 
Frontend development of the (current) future
Frontend development of the (current) futureFrontend development of the (current) future
Frontend development of the (current) future
 
Commerce and the browser in 2017
Commerce and the browser in 2017Commerce and the browser in 2017
Commerce and the browser in 2017
 
Frontend State of the union
Frontend State of the unionFrontend State of the union
Frontend State of the union
 
AngularJS best practices
AngularJS best practicesAngularJS best practices
AngularJS best practices
 
Frontend development of the (current) future
Frontend development of the (current) futureFrontend development of the (current) future
Frontend development of the (current) future
 
Observables - the why, what & how
Observables - the why, what & howObservables - the why, what & how
Observables - the why, what & how
 
Angular2 workshop
Angular2 workshopAngular2 workshop
Angular2 workshop
 
Progressive Web Apps og Payment Request
Progressive Web Apps og Payment RequestProgressive Web Apps og Payment Request
Progressive Web Apps og Payment Request
 
Spangulumbraco
SpangulumbracoSpangulumbraco
Spangulumbraco
 
Web development post io2016
Web development post io2016Web development post io2016
Web development post io2016
 
Observables in angular2
Observables in angular2Observables in angular2
Observables in angular2
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 

Building a dynamic SPA website with Angular