SlideShare uma empresa Scribd logo
1 de 36
Baixar para ler offline
Conquering AngularJS
Limitations
Valeri Karpov
Node.js Engineer, MongoDB
thecodebarbarian.com
github.com/vkarpov15
@code_barbarian
Turning Common Pain Points into Strengths
Who am I?
- AngularJS user since v0.9.4 (Dec 2010)
- Author of Professional AngularJS
- Currently working on an Ionic framework
blog series for StrongLoop
What is This Talk About?
•AngularJS is easy to get started with
•But there are some sticking points after PoC
• SEO
• Responsive layouts
• Integration testing
Part 1: Crawling a SPA
•Problem with JS-heavy pages
•Google only crawls HTML
•Appealing aspect of isomorphism (e.g. React)
•What to do with an AngularJS SPA?
Introducing Prerender
•Prerender.io
•Prerenders your page with PhantomJS for Google
•Easy to plug into Express, nginx, etc.
•Can pay for SaaS or host your own (open source!)
Setting Up A Basic SPA
Setting Up A Basic SPA
Express Web Server
•Can use nginx, python, etc.
•But easier with Express :)
•Render root view always because of HTML5 mode
Google AJAX Crawling
•Detailed spec by Google
•Note: recently deprecated after I wrote this talk
•With current setup, we only need one line
• HTML5 mode
• Express rendering root view for all routes
• And then we will add Prerender
Google AJAX Crawling
•Meta tag tells Google to re-send request
•Adds _escaped_fragment_ query parameter
Plugging Prerender In
•One-liner for Express
Prerender in Action
Fetch as Google
•Handy tool for making sure Google can crawl
Fetch as Google
•Crawl as Google doesn’t check meta tag for you
Why’s Prerender Good?
•Server-side rendering is hard in general for a SPA
•SPA’s do a lot of extra HTTP requests
• Stub them out?
• Let server make HTTP requests to itself?
•Angular 2.0 will do better
Why’s Prerender Bad?
•So slow
•window.prerenderReady helps
•In practice, you just cache it
•Prerender-node has good caching support
• In Amazon S3
• In server memory (risky)
Takeaways from Part 1
•Prerender makes SEO easy for AngularJS
•Or for any other non-isomorphic templating lib
•Plug and play with Express or nginx
• Also easy with koa if you use thunkify
•Detailed guide in Professional AngularJS Chapt 6
•But we live in a post-Mobilemageddon world
•What about responsiveness in AngularJS?
Responsive Layouts
•Layouts that reshape based on screen size
•Show/hide elements for small screens
•AngularJS is mostly “state-based”
•Scope variables determine what is displayed
• Controller needs to know about screen size :(
• JS and CSS need to be in sync
A Tale of Two Directives
•2 directives that toggle visibility
•Which one is more responsive, option A...
A Tale of Two Directives
•Or option B?
Directive B!
•Directive A is “state-based”
•Directive B is “reactive”
• Can target directive B with media queries
Scopes as Event Emitters
•Tragically underused AngularJS feature
•Scopes are powerful scoped event emitters!
•Directives are great for listening to scope events
Responsiveness Principle
•Use reactive for responsive layout elements
•Show/hide on events means media queries work
•Use state-based for URL changes
•(Probably) no overlap between the two
•You need both reactive and state-based
Part 2 Takeaways
•Directives will get run everywhere (Ionic)
•AngularJS code can be reactive
•Pretty useful for responsive layouts
•Directives should not know about screen size
• Re-usability
• Separation of concerns
• Performance ($digest loop on resize?)
Part 3: Integration Testing
- Good old-fashioned testing pyramid
????
Why Integration Tests
•Unit test: JS only
•Fast, but no DOM integration
•E2E test: full stack with DOM integration
•Slow, flakey, hard to shard and simulate errors
•“Does my UI actually work?”
•Fast feedback on development
How The Tests Will Work
•Test individual directives
•Directives easy to instantiate using $compile
•Run using Karma
• PhantomJS
• Sauce Labs
•Stub out HTTP so we can shard easily
How The Tests Will Work
•Test individual directives
•Directives easy to instantiate using $compile
•Run using Karma
• PhantomJS
• Sauce Labs
•Stub out HTTP so we can shard easily
Directive to Test
•Good ol’ toggle visibility directive B
•Huzzah, code re-use
Test Setup
•Karma - “launch a browser, load these files, report
output to shell”
Karma Config File
•Launch Google Chrome
•Load a bunch of files, including mocha + chai
•Report results to stdout
More About Karma
•Karma is a very deep subject
•Avoid going into too much detail in this talk
•See Chapter 9 of Professional AngularJS
•Testing Client Side JavaScript with Karma on
thecodebarbarian.com
Bootstrapping Directives
•New in AngularJS 1.3
•$compile service “Angularizes” HTML
JQuery Tests
•Now you have an HTML element, you can
• click
• blur
• or any other DOM event
•Also access AngularJS scopes, httpBackend, etc.
•Everything from TDD talk yesterday applies :)
Part 3 Takeaways
•Bootstrapping directives for tests is easy in >= 1.3
•Good for testing logic in AngularJS HTML
•Helps complete the picture for AngularJS testing
•Can also test SEO integration if you use Prerender
Thanks for Listening!
Comments, questions, haikus?
Read more at:
thecodebarbarian.com
github.com/vkarpov15
@code_barbarian

Mais conteúdo relacionado

Mais procurados

MEAN Stack - Google Developers Live 10/03/2013
MEAN Stack - Google Developers Live 10/03/2013MEAN Stack - Google Developers Live 10/03/2013
MEAN Stack - Google Developers Live 10/03/2013Valeri Karpov
 
JSFoo-2017 Takeaways
JSFoo-2017 TakeawaysJSFoo-2017 Takeaways
JSFoo-2017 TakeawaysMir Ali
 
[Blibli Brown Bag] Nodejs - The Other Side of Javascript
[Blibli Brown Bag] Nodejs - The Other Side of Javascript[Blibli Brown Bag] Nodejs - The Other Side of Javascript
[Blibli Brown Bag] Nodejs - The Other Side of JavascriptIrfan Maulana
 
SGCE 2012 Lightning Talk-Single Page Interface
SGCE 2012 Lightning Talk-Single Page InterfaceSGCE 2012 Lightning Talk-Single Page Interface
SGCE 2012 Lightning Talk-Single Page InterfaceDomingo Suarez Torres
 
The Dark Side of Single Page Applications
The Dark Side of Single Page ApplicationsThe Dark Side of Single Page Applications
The Dark Side of Single Page ApplicationsDor Kalev
 
PHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web DevelopmentPHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web DevelopmentIrfan Maulana
 
Next generation frontend tooling
Next generation frontend toolingNext generation frontend tooling
Next generation frontend toolingpksjce
 
Isomorphic web application
Isomorphic web applicationIsomorphic web application
Isomorphic web applicationOliver N
 
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...Valeri Karpov
 
Afrimadoni the power of docker
Afrimadoni   the power of dockerAfrimadoni   the power of docker
Afrimadoni the power of dockerPHP Indonesia
 
Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...
Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...
Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...Corey Clark, Ph.D.
 
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...Binary Studio
 
Bringing The Sexy Back To WebWorkers
Bringing The Sexy Back To WebWorkersBringing The Sexy Back To WebWorkers
Bringing The Sexy Back To WebWorkersCorey Clark, Ph.D.
 
What is Mean Stack Development ?
What is Mean Stack Development ?What is Mean Stack Development ?
What is Mean Stack Development ?Balajihope
 
MEAN Stack - Introduction & Advantages - Why should you switch to MEAN stack ...
MEAN Stack - Introduction & Advantages - Why should you switch to MEAN stack ...MEAN Stack - Introduction & Advantages - Why should you switch to MEAN stack ...
MEAN Stack - Introduction & Advantages - Why should you switch to MEAN stack ...Hariharan Ganesan
 

Mais procurados (19)

MEAN Stack - Google Developers Live 10/03/2013
MEAN Stack - Google Developers Live 10/03/2013MEAN Stack - Google Developers Live 10/03/2013
MEAN Stack - Google Developers Live 10/03/2013
 
JSFoo-2017 Takeaways
JSFoo-2017 TakeawaysJSFoo-2017 Takeaways
JSFoo-2017 Takeaways
 
Meanstack overview
Meanstack overviewMeanstack overview
Meanstack overview
 
[Blibli Brown Bag] Nodejs - The Other Side of Javascript
[Blibli Brown Bag] Nodejs - The Other Side of Javascript[Blibli Brown Bag] Nodejs - The Other Side of Javascript
[Blibli Brown Bag] Nodejs - The Other Side of Javascript
 
SGCE 2012 Lightning Talk-Single Page Interface
SGCE 2012 Lightning Talk-Single Page InterfaceSGCE 2012 Lightning Talk-Single Page Interface
SGCE 2012 Lightning Talk-Single Page Interface
 
The Dark Side of Single Page Applications
The Dark Side of Single Page ApplicationsThe Dark Side of Single Page Applications
The Dark Side of Single Page Applications
 
PHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web DevelopmentPHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web Development
 
Next generation frontend tooling
Next generation frontend toolingNext generation frontend tooling
Next generation frontend tooling
 
Isomorphic web application
Isomorphic web applicationIsomorphic web application
Isomorphic web application
 
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
 
Afrimadoni the power of docker
Afrimadoni   the power of dockerAfrimadoni   the power of docker
Afrimadoni the power of docker
 
MEAN Stack
MEAN StackMEAN Stack
MEAN Stack
 
Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...
Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...
Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...
 
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
Searching for the framework of my dreams in node.js ecosystem by Mykyta Semen...
 
The MEAN Stack
The MEAN StackThe MEAN Stack
The MEAN Stack
 
Node js projects
Node js projectsNode js projects
Node js projects
 
Bringing The Sexy Back To WebWorkers
Bringing The Sexy Back To WebWorkersBringing The Sexy Back To WebWorkers
Bringing The Sexy Back To WebWorkers
 
What is Mean Stack Development ?
What is Mean Stack Development ?What is Mean Stack Development ?
What is Mean Stack Development ?
 
MEAN Stack - Introduction & Advantages - Why should you switch to MEAN stack ...
MEAN Stack - Introduction & Advantages - Why should you switch to MEAN stack ...MEAN Stack - Introduction & Advantages - Why should you switch to MEAN stack ...
MEAN Stack - Introduction & Advantages - Why should you switch to MEAN stack ...
 

Destaque

MongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
MongoDB Miami Meetup 1/26/15: Introduction to WiredTigerMongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
MongoDB Miami Meetup 1/26/15: Introduction to WiredTigerValeri Karpov
 
JS-IL: Getting MEAN in 1 Hour
JS-IL: Getting MEAN in 1 HourJS-IL: Getting MEAN in 1 Hour
JS-IL: Getting MEAN in 1 HourValeri Karpov
 
Mongo db in 3 minutes BoilerMake
Mongo db in 3 minutes   BoilerMakeMongo db in 3 minutes   BoilerMake
Mongo db in 3 minutes BoilerMakeValeri Karpov
 
MongoDB Israel June Meetup
MongoDB Israel June MeetupMongoDB Israel June Meetup
MongoDB Israel June MeetupValeri Karpov
 
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and BeyondJS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and BeyondValeri Karpov
 
AngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous Integration
AngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous IntegrationAngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous Integration
AngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous IntegrationValeri Karpov
 
MongoDB: Queries and Aggregation Framework with NBA Game Data
MongoDB: Queries and Aggregation Framework with NBA Game DataMongoDB: Queries and Aggregation Framework with NBA Game Data
MongoDB: Queries and Aggregation Framework with NBA Game DataValeri Karpov
 
NodeSummit - MEAN Stack
NodeSummit - MEAN StackNodeSummit - MEAN Stack
NodeSummit - MEAN StackValeri Karpov
 
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)Valeri Karpov
 

Destaque (9)

MongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
MongoDB Miami Meetup 1/26/15: Introduction to WiredTigerMongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
MongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
 
JS-IL: Getting MEAN in 1 Hour
JS-IL: Getting MEAN in 1 HourJS-IL: Getting MEAN in 1 Hour
JS-IL: Getting MEAN in 1 Hour
 
Mongo db in 3 minutes BoilerMake
Mongo db in 3 minutes   BoilerMakeMongo db in 3 minutes   BoilerMake
Mongo db in 3 minutes BoilerMake
 
MongoDB Israel June Meetup
MongoDB Israel June MeetupMongoDB Israel June Meetup
MongoDB Israel June Meetup
 
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and BeyondJS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
 
AngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous Integration
AngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous IntegrationAngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous Integration
AngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous Integration
 
MongoDB: Queries and Aggregation Framework with NBA Game Data
MongoDB: Queries and Aggregation Framework with NBA Game DataMongoDB: Queries and Aggregation Framework with NBA Game Data
MongoDB: Queries and Aggregation Framework with NBA Game Data
 
NodeSummit - MEAN Stack
NodeSummit - MEAN StackNodeSummit - MEAN Stack
NodeSummit - MEAN Stack
 
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
 

Semelhante a Conquering AngularJS Limitations

Mvvm knockout vs angular
Mvvm knockout vs angularMvvm knockout vs angular
Mvvm knockout vs angularBasarat Syed
 
[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS
[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS
[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJSSrijan Technologies
 
How angularjs saves rails
How angularjs saves railsHow angularjs saves rails
How angularjs saves railsMichael He
 
Enterprise Strength Mobile JavaScript
Enterprise Strength Mobile JavaScriptEnterprise Strength Mobile JavaScript
Enterprise Strength Mobile JavaScriptTroy Miles
 
Swagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlierSwagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlierMiroslav Resetar
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners WorkshopSathish VJ
 
Intro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NETIntro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NETAlan Hecht
 
Single Page Applications - Desert Code Camp 2012
Single Page Applications - Desert Code Camp 2012Single Page Applications - Desert Code Camp 2012
Single Page Applications - Desert Code Camp 2012Adam Mokan
 
AngularJS One Day Workshop
AngularJS One Day WorkshopAngularJS One Day Workshop
AngularJS One Day WorkshopShyam Seshadri
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overviewJesse Warden
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project Elad Hirsch
 
Java EE 7 Soup to Nuts at JavaOne 2014
Java EE 7 Soup to Nuts at JavaOne 2014Java EE 7 Soup to Nuts at JavaOne 2014
Java EE 7 Soup to Nuts at JavaOne 2014Arun Gupta
 
OSGi and JavaScript - Simon Kaegi
OSGi and JavaScript - Simon KaegiOSGi and JavaScript - Simon Kaegi
OSGi and JavaScript - Simon Kaegimfrancis
 
JavaScript in Universal Windows Platform apps
JavaScript in Universal Windows Platform appsJavaScript in Universal Windows Platform apps
JavaScript in Universal Windows Platform appsTimmy Kokke
 
Meanstack Introduction by Kishore Chandra
Meanstack Introduction by Kishore ChandraMeanstack Introduction by Kishore Chandra
Meanstack Introduction by Kishore ChandraKishore Chandra
 
Gwt overview & getting started
Gwt overview & getting startedGwt overview & getting started
Gwt overview & getting startedBinh Bui
 

Semelhante a Conquering AngularJS Limitations (20)

Mvvm knockout vs angular
Mvvm knockout vs angularMvvm knockout vs angular
Mvvm knockout vs angular
 
[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS
[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS
[Srijan Wednesday Webinars] Developing Large Scale Applications in AngularJS
 
How angularjs saves rails
How angularjs saves railsHow angularjs saves rails
How angularjs saves rails
 
Enterprise Strength Mobile JavaScript
Enterprise Strength Mobile JavaScriptEnterprise Strength Mobile JavaScript
Enterprise Strength Mobile JavaScript
 
Mean stack
Mean stackMean stack
Mean stack
 
Swagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlierSwagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlier
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners Workshop
 
Intro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NETIntro to SPA using JavaScript & ASP.NET
Intro to SPA using JavaScript & ASP.NET
 
Single Page Applications - Desert Code Camp 2012
Single Page Applications - Desert Code Camp 2012Single Page Applications - Desert Code Camp 2012
Single Page Applications - Desert Code Camp 2012
 
AngularJS One Day Workshop
AngularJS One Day WorkshopAngularJS One Day Workshop
AngularJS One Day Workshop
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overview
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project 
 
Java EE 7 Soup to Nuts at JavaOne 2014
Java EE 7 Soup to Nuts at JavaOne 2014Java EE 7 Soup to Nuts at JavaOne 2014
Java EE 7 Soup to Nuts at JavaOne 2014
 
MEAN Stack
MEAN StackMEAN Stack
MEAN Stack
 
OSGi and JavaScript - Simon Kaegi
OSGi and JavaScript - Simon KaegiOSGi and JavaScript - Simon Kaegi
OSGi and JavaScript - Simon Kaegi
 
JavaScript in Universal Windows Platform apps
JavaScript in Universal Windows Platform appsJavaScript in Universal Windows Platform apps
JavaScript in Universal Windows Platform apps
 
Protractor survival guide
Protractor survival guideProtractor survival guide
Protractor survival guide
 
Meanstack Introduction by Kishore Chandra
Meanstack Introduction by Kishore ChandraMeanstack Introduction by Kishore Chandra
Meanstack Introduction by Kishore Chandra
 
Angular js
Angular jsAngular js
Angular js
 
Gwt overview & getting started
Gwt overview & getting startedGwt overview & getting started
Gwt overview & getting started
 

Mais de Valeri Karpov

A Practical Introduction to GeoJSON
A Practical Introduction to GeoJSONA Practical Introduction to GeoJSON
A Practical Introduction to GeoJSONValeri Karpov
 
A Practical Introduction to Functions-as-a-Service
A Practical Introduction to Functions-as-a-ServiceA Practical Introduction to Functions-as-a-Service
A Practical Introduction to Functions-as-a-ServiceValeri Karpov
 
A Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-ServiceA Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-ServiceValeri Karpov
 
Introducing Async/Await
Introducing Async/AwaitIntroducing Async/Await
Introducing Async/AwaitValeri Karpov
 
TAO and the Essence of Modern JavaScript
TAO and the Essence of Modern JavaScriptTAO and the Essence of Modern JavaScript
TAO and the Essence of Modern JavaScriptValeri Karpov
 
Mastering Async/Await in JavaScript
Mastering Async/Await in JavaScriptMastering Async/Await in JavaScript
Mastering Async/Await in JavaScriptValeri Karpov
 
React, Redux, and Archetype
React, Redux, and ArchetypeReact, Redux, and Archetype
React, Redux, and ArchetypeValeri Karpov
 
MongoDB API Talk @ HackPrinceton
MongoDB API Talk @ HackPrincetonMongoDB API Talk @ HackPrinceton
MongoDB API Talk @ HackPrincetonValeri Karpov
 

Mais de Valeri Karpov (8)

A Practical Introduction to GeoJSON
A Practical Introduction to GeoJSONA Practical Introduction to GeoJSON
A Practical Introduction to GeoJSON
 
A Practical Introduction to Functions-as-a-Service
A Practical Introduction to Functions-as-a-ServiceA Practical Introduction to Functions-as-a-Service
A Practical Introduction to Functions-as-a-Service
 
A Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-ServiceA Gentle Introduction to Functions-as-a-Service
A Gentle Introduction to Functions-as-a-Service
 
Introducing Async/Await
Introducing Async/AwaitIntroducing Async/Await
Introducing Async/Await
 
TAO and the Essence of Modern JavaScript
TAO and the Essence of Modern JavaScriptTAO and the Essence of Modern JavaScript
TAO and the Essence of Modern JavaScript
 
Mastering Async/Await in JavaScript
Mastering Async/Await in JavaScriptMastering Async/Await in JavaScript
Mastering Async/Await in JavaScript
 
React, Redux, and Archetype
React, Redux, and ArchetypeReact, Redux, and Archetype
React, Redux, and Archetype
 
MongoDB API Talk @ HackPrinceton
MongoDB API Talk @ HackPrincetonMongoDB API Talk @ HackPrinceton
MongoDB API Talk @ HackPrinceton
 

Último

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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 Processorsdebabhi2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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 RobisonAnna Loughnan Colquhoun
 

Último (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 

Conquering AngularJS Limitations

  • 1. Conquering AngularJS Limitations Valeri Karpov Node.js Engineer, MongoDB thecodebarbarian.com github.com/vkarpov15 @code_barbarian Turning Common Pain Points into Strengths
  • 2. Who am I? - AngularJS user since v0.9.4 (Dec 2010) - Author of Professional AngularJS - Currently working on an Ionic framework blog series for StrongLoop
  • 3. What is This Talk About? •AngularJS is easy to get started with •But there are some sticking points after PoC • SEO • Responsive layouts • Integration testing
  • 4. Part 1: Crawling a SPA •Problem with JS-heavy pages •Google only crawls HTML •Appealing aspect of isomorphism (e.g. React) •What to do with an AngularJS SPA?
  • 5. Introducing Prerender •Prerender.io •Prerenders your page with PhantomJS for Google •Easy to plug into Express, nginx, etc. •Can pay for SaaS or host your own (open source!)
  • 6. Setting Up A Basic SPA
  • 7. Setting Up A Basic SPA
  • 8. Express Web Server •Can use nginx, python, etc. •But easier with Express :) •Render root view always because of HTML5 mode
  • 9. Google AJAX Crawling •Detailed spec by Google •Note: recently deprecated after I wrote this talk •With current setup, we only need one line • HTML5 mode • Express rendering root view for all routes • And then we will add Prerender
  • 10. Google AJAX Crawling •Meta tag tells Google to re-send request •Adds _escaped_fragment_ query parameter
  • 13. Fetch as Google •Handy tool for making sure Google can crawl
  • 14. Fetch as Google •Crawl as Google doesn’t check meta tag for you
  • 15. Why’s Prerender Good? •Server-side rendering is hard in general for a SPA •SPA’s do a lot of extra HTTP requests • Stub them out? • Let server make HTTP requests to itself? •Angular 2.0 will do better
  • 16. Why’s Prerender Bad? •So slow •window.prerenderReady helps •In practice, you just cache it •Prerender-node has good caching support • In Amazon S3 • In server memory (risky)
  • 17. Takeaways from Part 1 •Prerender makes SEO easy for AngularJS •Or for any other non-isomorphic templating lib •Plug and play with Express or nginx • Also easy with koa if you use thunkify •Detailed guide in Professional AngularJS Chapt 6 •But we live in a post-Mobilemageddon world •What about responsiveness in AngularJS?
  • 18. Responsive Layouts •Layouts that reshape based on screen size •Show/hide elements for small screens •AngularJS is mostly “state-based” •Scope variables determine what is displayed • Controller needs to know about screen size :( • JS and CSS need to be in sync
  • 19. A Tale of Two Directives •2 directives that toggle visibility •Which one is more responsive, option A...
  • 20. A Tale of Two Directives •Or option B?
  • 21. Directive B! •Directive A is “state-based” •Directive B is “reactive” • Can target directive B with media queries
  • 22. Scopes as Event Emitters •Tragically underused AngularJS feature •Scopes are powerful scoped event emitters! •Directives are great for listening to scope events
  • 23. Responsiveness Principle •Use reactive for responsive layout elements •Show/hide on events means media queries work •Use state-based for URL changes •(Probably) no overlap between the two •You need both reactive and state-based
  • 24. Part 2 Takeaways •Directives will get run everywhere (Ionic) •AngularJS code can be reactive •Pretty useful for responsive layouts •Directives should not know about screen size • Re-usability • Separation of concerns • Performance ($digest loop on resize?)
  • 25. Part 3: Integration Testing - Good old-fashioned testing pyramid ????
  • 26. Why Integration Tests •Unit test: JS only •Fast, but no DOM integration •E2E test: full stack with DOM integration •Slow, flakey, hard to shard and simulate errors •“Does my UI actually work?” •Fast feedback on development
  • 27. How The Tests Will Work •Test individual directives •Directives easy to instantiate using $compile •Run using Karma • PhantomJS • Sauce Labs •Stub out HTTP so we can shard easily
  • 28. How The Tests Will Work •Test individual directives •Directives easy to instantiate using $compile •Run using Karma • PhantomJS • Sauce Labs •Stub out HTTP so we can shard easily
  • 29. Directive to Test •Good ol’ toggle visibility directive B •Huzzah, code re-use
  • 30. Test Setup •Karma - “launch a browser, load these files, report output to shell”
  • 31. Karma Config File •Launch Google Chrome •Load a bunch of files, including mocha + chai •Report results to stdout
  • 32. More About Karma •Karma is a very deep subject •Avoid going into too much detail in this talk •See Chapter 9 of Professional AngularJS •Testing Client Side JavaScript with Karma on thecodebarbarian.com
  • 33. Bootstrapping Directives •New in AngularJS 1.3 •$compile service “Angularizes” HTML
  • 34. JQuery Tests •Now you have an HTML element, you can • click • blur • or any other DOM event •Also access AngularJS scopes, httpBackend, etc. •Everything from TDD talk yesterday applies :)
  • 35. Part 3 Takeaways •Bootstrapping directives for tests is easy in >= 1.3 •Good for testing logic in AngularJS HTML •Helps complete the picture for AngularJS testing •Can also test SEO integration if you use Prerender
  • 36. Thanks for Listening! Comments, questions, haikus? Read more at: thecodebarbarian.com github.com/vkarpov15 @code_barbarian