SlideShare une entreprise Scribd logo
1  sur  40
Télécharger pour lire hors ligne
© 2013 SAP Portals. All rights reserved.
1
Lior Bar-On, Senior Development Architect @ SAP
Sept. 2013
Public
© 2013 SAP Portals. All rights reserved.
2
About Me


‫שלי‬ ‫הבלוג‬(‫בעברית‬:)http://www.softwarearchiblog.com/
http://www.linkedin.com/in/liorbo
© 2013 SAP Portals. All rights reserved.
3
Agenda
The Server
The Network
The Browser
© 2013 SAP Portals. All rights reserved.
4
The Network
The Network
The Server The Browser
© 2013 SAP Portals. All rights reserved.
5
A Web App that loads is a Miracle!
Load HTML file
DNS lookup
Establish TCP Conn. (3-way handshake)
HTTP request @Cold Connection
HTML Parsing starts
<script> tag => “Stop The World”
ForEach Script file:
 (Optional) DNS lookup
 (Optional) 3-way handshake + TLS handshake (“4-way”)
 (Optional) http request over a (cold) connection
Continue HTML parsing….
t
© 2013 SAP Portals. All rights reserved.
6
TCP Congestion Control: Slow Start (sending 20KB of data)
Cold Connection Warn Connection
Segment = 1460 bytes
Header = 40 bytes
© 2013 SAP Portals. All rights reserved.
7
An “Underwater Cable” won’t save ya!
© 2013 SAP Portals. All rights reserved.
8
How Does it works?
Hardware improves all the time
CPU / Memory
Network
Browsers Optimizations
Client-Side Cache
Keep Alive
DNS pre-fetch
TCO pre-connect
Network Optimizations: Content Delivery Networks (CDNs)
Developers can do much more!
© 2013 SAP Portals. All rights reserved.
9
Main Pain Point of Modern Networks: Latency
“average” latency is typically ~200ms, +200ms for 3G access
source
© 2013 SAP Portals. All rights reserved.
10
Tactics dealing with the Network
Reduce the number of Roundtrips
Lazy Loading
Caching
Domain Sharding
Unification
Minification
© 2013 SAP Portals. All rights reserved.
11
Tactic: Reduce number of Roundtrips / redirects
Latency is paid for each roundtrip done.
Eliminate (e.g. 404s, resources not being used)
Unify (later)
Lazy-Load (later)
Redirects require a new HTTP request cycle
Redirect = a significant waste
e.g. redirect to “m.mysite.com”
source: http archive
© 2013 SAP Portals. All rights reserved.
12
Tactic: Lazy Loading
Load resources (scripts, ajax calls, (images)) only when they are needed.
Dynamic JavaScript loading libraries:
 LABjs
 require.js
 Lsjs
 ControlJS
Manually: $('head').append( ... );
© 2013 SAP Portals. All rights reserved.
13
Tactic: Caching
Distinguish between “Cachable” vs. “Non-Cachable” HTTP Methods:
Some Methods (GET, HEAD) will be cached by the “network”
Unsafe Methods (POST, PUT, DELETE, OPTIONS) will not be cached by the “network”
Use appropriate HTTP headers to define a proper caching policy
Such as:
 Cache-control / expires
 If-Modified
 ETags
POST method can become cachable with proper headers, at least in theory
© 2013 SAP Portals. All rights reserved.
14
Domain Sharding
Distribute resources over multiple hostname to increase connection parallelism
Effectiveness is nowadays questionable (argument for, argument against)
Even if you do:
 Only on domains proven to require many files
 Shard no more than once
A new method rising: “Domain UnSharding”:
Assembling large, unique resources to a single host
can enjoy “connections warm-up”.
Images, fonts and niche JavaScript libraries
- are a good candidates
example.com = 1.1.1.1
img.example.com = 1.1.1.1
DNS
Browser
consult
6 x example.com
6 x img.example.com
Overall: 12 connections!
<< 1.1.1.1 >>
Server
connections:
© 2013 SAP Portals. All rights reserved.
15
Tactic: Unification
Working with small source files is a good programming practice.
So - crunch JavaScript and CSS files
Yahoo’s YUI Compressor
Google Closure Compiler
CSSO (for CSS files)
etc.
source: http archive
© 2013 SAP Portals. All rights reserved.
16
Tactic: Unification (2)
Sprites
Create 1 image to replace many
Not just for image files (e.g. howler.js)
Data URIs
Note: DataURI increase resource size by 37%
© 2013 SAP Portals. All rights reserved.
17
Tactic: Minification
JavaScript Minification tools can reduce 50%-90% of the file’s size
Being compressed into:
© 2013 SAP Portals. All rights reserved.
18
Tactic: Minification(2)
CSS minification tools can reduce 30%-50% of the file’s size
Optimize images size and compression - can save much size.
Enabling GZIP compression on textual files (even if minified) can save you some network bytes.
Bitmap
Vector SVG
JPG
compression?
PNG
Bit depth?
Lossy PNG
?
?
?
Bitmap
reduce size?
?
?
© 2013 SAP Portals. All rights reserved.
19
Real Life Experience
© 2013 SAP Portals. All rights reserved.
20
WebPageTest: Results
© 2013 SAP Portals. All rights reserved.
21
WebPageTest: Some Data provided
© 2013 SAP Portals. All rights reserved.
22
WebPageTest: Connection View
© 2013 SAP Portals. All rights reserved.
23
Inbound Alternative: Chrome Dev Tools
© 2013 SAP Portals. All rights reserved.
24
The Browser
The Network
The Server The Browser
© 2013 SAP Portals. All rights reserved.
25
The Web Browser
source: statcounter
© 2013 SAP Portals. All rights reserved.
26
The Browser Internals - engines
Browser Rendering Engine
Safari (iOS, win or Mac) Webkit
Chrome, Opera Blink (a recent fork of Webkit)
Firefox Gecko
Internet Explorer Trident
Internet Explorer for Mac Tasman
Browser JavaScript Engine ECMAScript 5.1
Support since
Safari (iOS, win or Mac) javaScriptCore (aka Nitro) SF5.1*
Chrome, Opera V8 Chrome13
Firefox
SpiderMonkey
JIT part called ionMoney (since
FF18)
FF4
Internet Explorer Chakra (since IE9) IE9*
© 2013 SAP Portals. All rights reserved.
27
Typical Browser HTML rendering flow
HTML file
DOM Tree
(aka content model)
1: parse
Style Tree
(aka style ruleSet, CSSOM)
CSS file 2: parse
2: load
Render Tree
(aka frame tree)
3: merge
3: merge
Canvas
5: render
Layout
4: layout /
re-flow
JavaScript file
2: update
2: update
2: load
6: draw
on screen
Source: d.baron
© 2013 SAP Portals. All rights reserved.
28
Problems that may occur with the Browser’s Rendering Model
“Stop the World” on initial page load
Doing Unnecessary work (“Layout trashing”, “Paint trashing”)
Single thread
The Browser is not well-known to developers
© 2013 SAP Portals. All rights reserved.
29
“Stop The World”
blocks other downloads (images in IE, iframes); scripts are loaded and executed serially; blocks rendering
during parse-execute
© 2013 SAP Portals. All rights reserved.
30
3 interaction milestones
0.1 second
is about the limit for having the user feel that the system is reacting instantaneously, meaning that no special
feedback is necessary except to display the result.
1.0 second
is about the limit for the user's flow of thought to stay uninterrupted, even though the user will notice the
delay. Normally, no special feedback is necessary during delays of more than 0.1 but less than 1.0 second,
but the user does lose the feeling of operating directly on the data.
10 seconds
is about the limit for keeping the user's attention focused on the dialogue. For longer delays, users will want
to perform other tasks while waiting for the computer to finish, so they should be given feedback indicating
when the computer expects to be done. Feedback during the delay is especially important if the response
time is likely to be highly variable, since users will then not know what to expect.
© 2013 SAP Portals. All rights reserved.
31
Tactics dealing with the Browser
Postpone Script Execution
Add styles before DOM Elements
Be aware of DOM Tree’s Write Buffer
Offload work to other threads
© 2013 SAP Portals. All rights reserved.
32
Tactic: Postpone Script Execution
Either:
 Move Script to the end of the file (after <body> tag)
 Add Script Dynamically to <head> tag:
$('head').append( ... );
 Use “async” and “defer” attributes
<script src=“…” async></script>
 Simply, use require.js / LABjs / etc.
© 2013 SAP Portals. All rights reserved.
33
Tactic: Add styles before DOM Elements
Inserting Style tree element is more expensive than inserting DOM element.
We also want nice visualization on the screen early (perceived performance)
Therefore:
 Inside the <HEAD>, put all CSS files first.
 Prefer jQuery’s data() over addClass()
 Minimize use of CSSOM, e.g.:
myStyle.insertRule(…)
DOM Tree
(aka content model)
Style Tree
(aka style ruleSet, CSSOM)
Render Tree
(aka frame tree)
3: merge
3: merge
© 2013 SAP Portals. All rights reserved.
34
2 Code Examples…
Which Example looks Much better for performance?
© 2013 SAP Portals. All rights reserved.
35
Tactic: Be aware of DOM Tree’s Write Buffer
A little theory:
Flush will happen:
 At DOM read operation, e.g. element.height
 Every 16.6ms (to achieve 60fps)
Style Tree DOM Tree
Render Tree
DOM API
Read (B)
Write Buffer
Read (A)
write
Flush changes
derived fromderived from
© 2013 SAP Portals. All rights reserved.
36
Tactic: Be aware of DOM Tree’s Write Buffer (2)
R/W/R/W/R/W/R/W/R/W = ~250ms
RRRRRRR/WWWWWW = ~20ms
source
© 2013 SAP Portals. All rights reserved.
37
Another example
Could be so much better as:
© 2013 SAP Portals. All rights reserved.
38
Tactic: offload work to other threads
Browser has a single thread that executes JavaScript (per browser tab)
When the thread is busy, the following is being blocked:
Event handling (e.g. Click, Resize)
setTimeout / setInterval
Possibly rendering
What can be done?
SetTimeout(myFunc, 0);
Use CSS Animations
transform: translateZ(0); read more
Use Web Workers for intensive calculations / network activity
Heap
Queue
Stack
Thread
Closure
Closure
Closure
Closure
Closure
Closure
Closure
Closure
Closure
Closure
global variables
Context
(“window” object)
public part
private part
pull
push
“document” object
(DOM)
© 2013 SAP Portals. All rights reserved.
39
Chrome Dev Tools’ Timeline is your best friend
© 2013 SAP Portals. All rights reserved.
40
Thank You
Lior Bar-On
baronlior@gmail.com
(Hebrew) Blog: http://www.softwarearchiblog.com/

Contenu connexe

Tendances

Microservices architecture overview v3
Microservices architecture overview v3Microservices architecture overview v3
Microservices architecture overview v3Dmitry Skaredov
 
Pivotal cloud cache for .net microservices
Pivotal cloud cache for .net microservicesPivotal cloud cache for .net microservices
Pivotal cloud cache for .net microservicesJagdish Mirani
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architectureFaren faren
 
Deconstructing Monoliths with Domain Driven Design
Deconstructing Monoliths with Domain Driven DesignDeconstructing Monoliths with Domain Driven Design
Deconstructing Monoliths with Domain Driven DesignVMware Tanzu
 
Y. Tsesmelis, Uni Systems: Quarkus use cases and business value
Y. Tsesmelis, Uni Systems: Quarkus use cases and business valueY. Tsesmelis, Uni Systems: Quarkus use cases and business value
Y. Tsesmelis, Uni Systems: Quarkus use cases and business valueUni Systems S.M.S.A.
 
Building Services with WSO2 Application Server and WSO2 Microservices Framewo...
Building Services with WSO2 Application Server and WSO2 Microservices Framewo...Building Services with WSO2 Application Server and WSO2 Microservices Framewo...
Building Services with WSO2 Application Server and WSO2 Microservices Framewo...Sagara Gunathunga
 
Microservices with Node.js and RabbitMQ
Microservices with Node.js and RabbitMQMicroservices with Node.js and RabbitMQ
Microservices with Node.js and RabbitMQPaulius Uza
 
Microservices in Action
Microservices in ActionMicroservices in Action
Microservices in ActionBhagwat Kumar
 
Microservices with Node.js and Apache Cassandra
Microservices with Node.js and Apache CassandraMicroservices with Node.js and Apache Cassandra
Microservices with Node.js and Apache CassandraJorge Bay Gondra
 
Microservices architecture examples
Microservices architecture examplesMicroservices architecture examples
Microservices architecture examplesChanny Yun
 
GDG Cloud Southlake #9 Secure Cloud Networking - Beyond Cloud Boundaries
GDG Cloud Southlake #9 Secure Cloud Networking - Beyond Cloud BoundariesGDG Cloud Southlake #9 Secure Cloud Networking - Beyond Cloud Boundaries
GDG Cloud Southlake #9 Secure Cloud Networking - Beyond Cloud BoundariesJames Anderson
 
#JaxLondon keynote: Developing applications with a microservice architecture
#JaxLondon keynote: Developing applications with a microservice architecture#JaxLondon keynote: Developing applications with a microservice architecture
#JaxLondon keynote: Developing applications with a microservice architectureChris Richardson
 
Safe cloud native transformation approaches
Safe cloud native transformation approachesSafe cloud native transformation approaches
Safe cloud native transformation approachesuEngine Solutions
 
Achieving Cost and Resource Efficiency through Docker, OpenShift and Kubernetes
Achieving Cost and Resource Efficiency through Docker, OpenShift and KubernetesAchieving Cost and Resource Efficiency through Docker, OpenShift and Kubernetes
Achieving Cost and Resource Efficiency through Docker, OpenShift and KubernetesDean Delamont
 
Bring Service Mesh To Cloud Native-apps
Bring Service Mesh To Cloud Native-appsBring Service Mesh To Cloud Native-apps
Bring Service Mesh To Cloud Native-appsThang Chung
 
Multi tier, multi-tenant, multi-problem kafka
Multi tier, multi-tenant, multi-problem kafkaMulti tier, multi-tenant, multi-problem kafka
Multi tier, multi-tenant, multi-problem kafkaTodd Palino
 
Understanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring BootUnderstanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring BootKashif Ali Siddiqui
 

Tendances (20)

Microservices architecture overview v3
Microservices architecture overview v3Microservices architecture overview v3
Microservices architecture overview v3
 
Pivotal cloud cache for .net microservices
Pivotal cloud cache for .net microservicesPivotal cloud cache for .net microservices
Pivotal cloud cache for .net microservices
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architecture
 
Deconstructing Monoliths with Domain Driven Design
Deconstructing Monoliths with Domain Driven DesignDeconstructing Monoliths with Domain Driven Design
Deconstructing Monoliths with Domain Driven Design
 
Y. Tsesmelis, Uni Systems: Quarkus use cases and business value
Y. Tsesmelis, Uni Systems: Quarkus use cases and business valueY. Tsesmelis, Uni Systems: Quarkus use cases and business value
Y. Tsesmelis, Uni Systems: Quarkus use cases and business value
 
Building Services with WSO2 Application Server and WSO2 Microservices Framewo...
Building Services with WSO2 Application Server and WSO2 Microservices Framewo...Building Services with WSO2 Application Server and WSO2 Microservices Framewo...
Building Services with WSO2 Application Server and WSO2 Microservices Framewo...
 
Microservices with Node.js and RabbitMQ
Microservices with Node.js and RabbitMQMicroservices with Node.js and RabbitMQ
Microservices with Node.js and RabbitMQ
 
Microservices in Action
Microservices in ActionMicroservices in Action
Microservices in Action
 
Microservices with Node.js and Apache Cassandra
Microservices with Node.js and Apache CassandraMicroservices with Node.js and Apache Cassandra
Microservices with Node.js and Apache Cassandra
 
Microservices architecture examples
Microservices architecture examplesMicroservices architecture examples
Microservices architecture examples
 
GDG Cloud Southlake #9 Secure Cloud Networking - Beyond Cloud Boundaries
GDG Cloud Southlake #9 Secure Cloud Networking - Beyond Cloud BoundariesGDG Cloud Southlake #9 Secure Cloud Networking - Beyond Cloud Boundaries
GDG Cloud Southlake #9 Secure Cloud Networking - Beyond Cloud Boundaries
 
#JaxLondon keynote: Developing applications with a microservice architecture
#JaxLondon keynote: Developing applications with a microservice architecture#JaxLondon keynote: Developing applications with a microservice architecture
#JaxLondon keynote: Developing applications with a microservice architecture
 
Safe cloud native transformation approaches
Safe cloud native transformation approachesSafe cloud native transformation approaches
Safe cloud native transformation approaches
 
Achieving Cost and Resource Efficiency through Docker, OpenShift and Kubernetes
Achieving Cost and Resource Efficiency through Docker, OpenShift and KubernetesAchieving Cost and Resource Efficiency through Docker, OpenShift and Kubernetes
Achieving Cost and Resource Efficiency through Docker, OpenShift and Kubernetes
 
Be DevOps Ready
Be DevOps ReadyBe DevOps Ready
Be DevOps Ready
 
Azure Service Fabric Overview
Azure Service Fabric OverviewAzure Service Fabric Overview
Azure Service Fabric Overview
 
Bring Service Mesh To Cloud Native-apps
Bring Service Mesh To Cloud Native-appsBring Service Mesh To Cloud Native-apps
Bring Service Mesh To Cloud Native-apps
 
Spring Into the Cloud
Spring Into the CloudSpring Into the Cloud
Spring Into the Cloud
 
Multi tier, multi-tenant, multi-problem kafka
Multi tier, multi-tenant, multi-problem kafkaMulti tier, multi-tenant, multi-problem kafka
Multi tier, multi-tenant, multi-problem kafka
 
Understanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring BootUnderstanding MicroSERVICE Architecture with Java & Spring Boot
Understanding MicroSERVICE Architecture with Java & Spring Boot
 

Similaire à Get to know the browser better and write faster web apps

SAS on Your (Apache) Cluster, Serving your Data (Analysts)
SAS on Your (Apache) Cluster, Serving your Data (Analysts)SAS on Your (Apache) Cluster, Serving your Data (Analysts)
SAS on Your (Apache) Cluster, Serving your Data (Analysts)DataWorks Summit
 
Hadoop workshop
Hadoop workshopHadoop workshop
Hadoop workshopFang Mac
 
Design Choices for Cloud Data Platforms
Design Choices for Cloud Data PlatformsDesign Choices for Cloud Data Platforms
Design Choices for Cloud Data PlatformsAshish Mrig
 
Hadoop Technical Presentation
Hadoop Technical PresentationHadoop Technical Presentation
Hadoop Technical PresentationErwan Alliaume
 
Big and Fast Data - Building Infinitely Scalable Systems
Big and Fast Data - Building Infinitely Scalable SystemsBig and Fast Data - Building Infinitely Scalable Systems
Big and Fast Data - Building Infinitely Scalable SystemsFred Melo
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal PerformancesVladimir Ilic
 
Put is the new rename: San Jose Summit Edition
Put is the new rename: San Jose Summit EditionPut is the new rename: San Jose Summit Edition
Put is the new rename: San Jose Summit EditionSteve Loughran
 
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010Bhupesh Bansal
 
Hadoop and Voldemort @ LinkedIn
Hadoop and Voldemort @ LinkedInHadoop and Voldemort @ LinkedIn
Hadoop and Voldemort @ LinkedInHadoop User Group
 
Sql on everything with drill
Sql on everything with drillSql on everything with drill
Sql on everything with drillJulien Le Dem
 
DrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizingDrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizingAshok Modi
 
UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015Christopher Curtin
 
Web Speed And Scalability
Web Speed And ScalabilityWeb Speed And Scalability
Web Speed And ScalabilityJason Ragsdale
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalabilityTwinbit
 
Optimize Data Connectivity in .NET Applications
Optimize Data Connectivity in .NET ApplicationsOptimize Data Connectivity in .NET Applications
Optimize Data Connectivity in .NET ApplicationsAbhishek Kant
 
PUT is the new rename()
PUT is the new rename()PUT is the new rename()
PUT is the new rename()Steve Loughran
 
Building high performing web pages
Building high performing web pagesBuilding high performing web pages
Building high performing web pagesNilesh Bafna
 
Windows Azure Platform + PHP - Jonathan Wong
Windows Azure Platform + PHP - Jonathan WongWindows Azure Platform + PHP - Jonathan Wong
Windows Azure Platform + PHP - Jonathan WongSpiffy
 

Similaire à Get to know the browser better and write faster web apps (20)

SAS on Your (Apache) Cluster, Serving your Data (Analysts)
SAS on Your (Apache) Cluster, Serving your Data (Analysts)SAS on Your (Apache) Cluster, Serving your Data (Analysts)
SAS on Your (Apache) Cluster, Serving your Data (Analysts)
 
Hadoop workshop
Hadoop workshopHadoop workshop
Hadoop workshop
 
Scaling 101 test
Scaling 101 testScaling 101 test
Scaling 101 test
 
Scaling 101
Scaling 101Scaling 101
Scaling 101
 
Design Choices for Cloud Data Platforms
Design Choices for Cloud Data PlatformsDesign Choices for Cloud Data Platforms
Design Choices for Cloud Data Platforms
 
Hadoop Technical Presentation
Hadoop Technical PresentationHadoop Technical Presentation
Hadoop Technical Presentation
 
Big and Fast Data - Building Infinitely Scalable Systems
Big and Fast Data - Building Infinitely Scalable SystemsBig and Fast Data - Building Infinitely Scalable Systems
Big and Fast Data - Building Infinitely Scalable Systems
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal Performances
 
Put is the new rename: San Jose Summit Edition
Put is the new rename: San Jose Summit EditionPut is the new rename: San Jose Summit Edition
Put is the new rename: San Jose Summit Edition
 
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
Voldemort & Hadoop @ Linkedin, Hadoop User Group Jan 2010
 
Hadoop and Voldemort @ LinkedIn
Hadoop and Voldemort @ LinkedInHadoop and Voldemort @ LinkedIn
Hadoop and Voldemort @ LinkedIn
 
Sql on everything with drill
Sql on everything with drillSql on everything with drill
Sql on everything with drill
 
DrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizingDrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizing
 
UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015
 
Web Speed And Scalability
Web Speed And ScalabilityWeb Speed And Scalability
Web Speed And Scalability
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalability
 
Optimize Data Connectivity in .NET Applications
Optimize Data Connectivity in .NET ApplicationsOptimize Data Connectivity in .NET Applications
Optimize Data Connectivity in .NET Applications
 
PUT is the new rename()
PUT is the new rename()PUT is the new rename()
PUT is the new rename()
 
Building high performing web pages
Building high performing web pagesBuilding high performing web pages
Building high performing web pages
 
Windows Azure Platform + PHP - Jonathan Wong
Windows Azure Platform + PHP - Jonathan WongWindows Azure Platform + PHP - Jonathan Wong
Windows Azure Platform + PHP - Jonathan Wong
 

Dernier

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
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 DevelopmentsTrustArc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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.pdfsudhanshuwaghmare1
 
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
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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...Miguel Araújo
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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 2024The Digital Insurer
 
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 FresherRemote DBA Services
 

Dernier (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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...
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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
 
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
 

Get to know the browser better and write faster web apps

  • 1. © 2013 SAP Portals. All rights reserved. 1 Lior Bar-On, Senior Development Architect @ SAP Sept. 2013 Public
  • 2. © 2013 SAP Portals. All rights reserved. 2 About Me   ‫שלי‬ ‫הבלוג‬(‫בעברית‬:)http://www.softwarearchiblog.com/ http://www.linkedin.com/in/liorbo
  • 3. © 2013 SAP Portals. All rights reserved. 3 Agenda The Server The Network The Browser
  • 4. © 2013 SAP Portals. All rights reserved. 4 The Network The Network The Server The Browser
  • 5. © 2013 SAP Portals. All rights reserved. 5 A Web App that loads is a Miracle! Load HTML file DNS lookup Establish TCP Conn. (3-way handshake) HTTP request @Cold Connection HTML Parsing starts <script> tag => “Stop The World” ForEach Script file:  (Optional) DNS lookup  (Optional) 3-way handshake + TLS handshake (“4-way”)  (Optional) http request over a (cold) connection Continue HTML parsing…. t
  • 6. © 2013 SAP Portals. All rights reserved. 6 TCP Congestion Control: Slow Start (sending 20KB of data) Cold Connection Warn Connection Segment = 1460 bytes Header = 40 bytes
  • 7. © 2013 SAP Portals. All rights reserved. 7 An “Underwater Cable” won’t save ya!
  • 8. © 2013 SAP Portals. All rights reserved. 8 How Does it works? Hardware improves all the time CPU / Memory Network Browsers Optimizations Client-Side Cache Keep Alive DNS pre-fetch TCO pre-connect Network Optimizations: Content Delivery Networks (CDNs) Developers can do much more!
  • 9. © 2013 SAP Portals. All rights reserved. 9 Main Pain Point of Modern Networks: Latency “average” latency is typically ~200ms, +200ms for 3G access source
  • 10. © 2013 SAP Portals. All rights reserved. 10 Tactics dealing with the Network Reduce the number of Roundtrips Lazy Loading Caching Domain Sharding Unification Minification
  • 11. © 2013 SAP Portals. All rights reserved. 11 Tactic: Reduce number of Roundtrips / redirects Latency is paid for each roundtrip done. Eliminate (e.g. 404s, resources not being used) Unify (later) Lazy-Load (later) Redirects require a new HTTP request cycle Redirect = a significant waste e.g. redirect to “m.mysite.com” source: http archive
  • 12. © 2013 SAP Portals. All rights reserved. 12 Tactic: Lazy Loading Load resources (scripts, ajax calls, (images)) only when they are needed. Dynamic JavaScript loading libraries:  LABjs  require.js  Lsjs  ControlJS Manually: $('head').append( ... );
  • 13. © 2013 SAP Portals. All rights reserved. 13 Tactic: Caching Distinguish between “Cachable” vs. “Non-Cachable” HTTP Methods: Some Methods (GET, HEAD) will be cached by the “network” Unsafe Methods (POST, PUT, DELETE, OPTIONS) will not be cached by the “network” Use appropriate HTTP headers to define a proper caching policy Such as:  Cache-control / expires  If-Modified  ETags POST method can become cachable with proper headers, at least in theory
  • 14. © 2013 SAP Portals. All rights reserved. 14 Domain Sharding Distribute resources over multiple hostname to increase connection parallelism Effectiveness is nowadays questionable (argument for, argument against) Even if you do:  Only on domains proven to require many files  Shard no more than once A new method rising: “Domain UnSharding”: Assembling large, unique resources to a single host can enjoy “connections warm-up”. Images, fonts and niche JavaScript libraries - are a good candidates example.com = 1.1.1.1 img.example.com = 1.1.1.1 DNS Browser consult 6 x example.com 6 x img.example.com Overall: 12 connections! << 1.1.1.1 >> Server connections:
  • 15. © 2013 SAP Portals. All rights reserved. 15 Tactic: Unification Working with small source files is a good programming practice. So - crunch JavaScript and CSS files Yahoo’s YUI Compressor Google Closure Compiler CSSO (for CSS files) etc. source: http archive
  • 16. © 2013 SAP Portals. All rights reserved. 16 Tactic: Unification (2) Sprites Create 1 image to replace many Not just for image files (e.g. howler.js) Data URIs Note: DataURI increase resource size by 37%
  • 17. © 2013 SAP Portals. All rights reserved. 17 Tactic: Minification JavaScript Minification tools can reduce 50%-90% of the file’s size Being compressed into:
  • 18. © 2013 SAP Portals. All rights reserved. 18 Tactic: Minification(2) CSS minification tools can reduce 30%-50% of the file’s size Optimize images size and compression - can save much size. Enabling GZIP compression on textual files (even if minified) can save you some network bytes. Bitmap Vector SVG JPG compression? PNG Bit depth? Lossy PNG ? ? ? Bitmap reduce size? ? ?
  • 19. © 2013 SAP Portals. All rights reserved. 19 Real Life Experience
  • 20. © 2013 SAP Portals. All rights reserved. 20 WebPageTest: Results
  • 21. © 2013 SAP Portals. All rights reserved. 21 WebPageTest: Some Data provided
  • 22. © 2013 SAP Portals. All rights reserved. 22 WebPageTest: Connection View
  • 23. © 2013 SAP Portals. All rights reserved. 23 Inbound Alternative: Chrome Dev Tools
  • 24. © 2013 SAP Portals. All rights reserved. 24 The Browser The Network The Server The Browser
  • 25. © 2013 SAP Portals. All rights reserved. 25 The Web Browser source: statcounter
  • 26. © 2013 SAP Portals. All rights reserved. 26 The Browser Internals - engines Browser Rendering Engine Safari (iOS, win or Mac) Webkit Chrome, Opera Blink (a recent fork of Webkit) Firefox Gecko Internet Explorer Trident Internet Explorer for Mac Tasman Browser JavaScript Engine ECMAScript 5.1 Support since Safari (iOS, win or Mac) javaScriptCore (aka Nitro) SF5.1* Chrome, Opera V8 Chrome13 Firefox SpiderMonkey JIT part called ionMoney (since FF18) FF4 Internet Explorer Chakra (since IE9) IE9*
  • 27. © 2013 SAP Portals. All rights reserved. 27 Typical Browser HTML rendering flow HTML file DOM Tree (aka content model) 1: parse Style Tree (aka style ruleSet, CSSOM) CSS file 2: parse 2: load Render Tree (aka frame tree) 3: merge 3: merge Canvas 5: render Layout 4: layout / re-flow JavaScript file 2: update 2: update 2: load 6: draw on screen Source: d.baron
  • 28. © 2013 SAP Portals. All rights reserved. 28 Problems that may occur with the Browser’s Rendering Model “Stop the World” on initial page load Doing Unnecessary work (“Layout trashing”, “Paint trashing”) Single thread The Browser is not well-known to developers
  • 29. © 2013 SAP Portals. All rights reserved. 29 “Stop The World” blocks other downloads (images in IE, iframes); scripts are loaded and executed serially; blocks rendering during parse-execute
  • 30. © 2013 SAP Portals. All rights reserved. 30 3 interaction milestones 0.1 second is about the limit for having the user feel that the system is reacting instantaneously, meaning that no special feedback is necessary except to display the result. 1.0 second is about the limit for the user's flow of thought to stay uninterrupted, even though the user will notice the delay. Normally, no special feedback is necessary during delays of more than 0.1 but less than 1.0 second, but the user does lose the feeling of operating directly on the data. 10 seconds is about the limit for keeping the user's attention focused on the dialogue. For longer delays, users will want to perform other tasks while waiting for the computer to finish, so they should be given feedback indicating when the computer expects to be done. Feedback during the delay is especially important if the response time is likely to be highly variable, since users will then not know what to expect.
  • 31. © 2013 SAP Portals. All rights reserved. 31 Tactics dealing with the Browser Postpone Script Execution Add styles before DOM Elements Be aware of DOM Tree’s Write Buffer Offload work to other threads
  • 32. © 2013 SAP Portals. All rights reserved. 32 Tactic: Postpone Script Execution Either:  Move Script to the end of the file (after <body> tag)  Add Script Dynamically to <head> tag: $('head').append( ... );  Use “async” and “defer” attributes <script src=“…” async></script>  Simply, use require.js / LABjs / etc.
  • 33. © 2013 SAP Portals. All rights reserved. 33 Tactic: Add styles before DOM Elements Inserting Style tree element is more expensive than inserting DOM element. We also want nice visualization on the screen early (perceived performance) Therefore:  Inside the <HEAD>, put all CSS files first.  Prefer jQuery’s data() over addClass()  Minimize use of CSSOM, e.g.: myStyle.insertRule(…) DOM Tree (aka content model) Style Tree (aka style ruleSet, CSSOM) Render Tree (aka frame tree) 3: merge 3: merge
  • 34. © 2013 SAP Portals. All rights reserved. 34 2 Code Examples… Which Example looks Much better for performance?
  • 35. © 2013 SAP Portals. All rights reserved. 35 Tactic: Be aware of DOM Tree’s Write Buffer A little theory: Flush will happen:  At DOM read operation, e.g. element.height  Every 16.6ms (to achieve 60fps) Style Tree DOM Tree Render Tree DOM API Read (B) Write Buffer Read (A) write Flush changes derived fromderived from
  • 36. © 2013 SAP Portals. All rights reserved. 36 Tactic: Be aware of DOM Tree’s Write Buffer (2) R/W/R/W/R/W/R/W/R/W = ~250ms RRRRRRR/WWWWWW = ~20ms source
  • 37. © 2013 SAP Portals. All rights reserved. 37 Another example Could be so much better as:
  • 38. © 2013 SAP Portals. All rights reserved. 38 Tactic: offload work to other threads Browser has a single thread that executes JavaScript (per browser tab) When the thread is busy, the following is being blocked: Event handling (e.g. Click, Resize) setTimeout / setInterval Possibly rendering What can be done? SetTimeout(myFunc, 0); Use CSS Animations transform: translateZ(0); read more Use Web Workers for intensive calculations / network activity Heap Queue Stack Thread Closure Closure Closure Closure Closure Closure Closure Closure Closure Closure global variables Context (“window” object) public part private part pull push “document” object (DOM)
  • 39. © 2013 SAP Portals. All rights reserved. 39 Chrome Dev Tools’ Timeline is your best friend
  • 40. © 2013 SAP Portals. All rights reserved. 40 Thank You Lior Bar-On baronlior@gmail.com (Hebrew) Blog: http://www.softwarearchiblog.com/