SlideShare a Scribd company logo
1 of 17
Building High Performance Web Apps.
Essential rules and common practice
Author: Arshak Movsisyan
Email: arshak.movsissian@gmail.com
5 Rules For High Performance
1. Use a Content Delivery Network (CDN)
2. Add an Expires or a Cache-Control Header
3. Work with Scripts (Make External, Position, Group,
Minify, Compress)
4. Reduce the Number of DOM Elements
5. Develop Smart Event Handlers
1. Use a CDN
What is CDN?
CDN is a collection of web servers distributed across multiple locations to
deliver content more efficiently to users. E.g. CloudFlare, Coral Content
Distribution Network, Incapsula, etc.
How CDN works?
The server with the fewest network hops or the server with the quickest
response time is chosen.
Results
Researches showed that it improves end-user response times by 20% or
more, meanwhile 80-90% of the end-user response time is spent
downloading all the components in the page: images, stylesheets, scripts,
etc.
2. Add an Expires or a Cache-Control Header
For static components: implement "Never expire" policy by setting far
future Expires header.
Example: Expires: Thu, 15 Apr 2020 20:00:00 GMT
But keep in mind, if you use a far future Expires header you have to change the component's filename
whenever the component changes.
For dynamic components: use an appropriate Cache-Control header to help the
browser with conditional requests
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=290304000, public"
</FilesMatch>
This goes in your root .htaccess file but if you have access to httpd.conf that is better.
3. Work with Scripts - Make JavaScript and CSS External
Why making scripts external is faster?
Using external files generally produces faster pages because the JavaScript
and CSS files are cached by the browser.
Results
External files are cached by the browser, the size of the HTML document is
reduced without increasing the number of HTTP requests.
3. Work with Scripts – Positioning JavaScript and CSS
How do we generally position scripts?
<html>
<head>
<title>Positioning Scripts</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src=“//cdnjs.cloudflare.com/js/script_1.js"></script>
<script type="text/javascript" src=“//cdnjs.cloudflare.com/js/script_2.js"></script>
<script type="text/javascript" src=“//cdnjs.cloudflare.com/js/script_3.js"></script>
</head>
<body>
<p>Not a good practice!</p>
</body>
</html>
3. Work with Scripts – Positioning JavaScript and CSS
Code Execution Flow
Each file must wait until the previous one has been downloaded and executed before the next download can
begin. In the meantime, the user is met with a blank screen as the files are being downloaded one at a time.
This is the behavior of most major browsers today.
How it works.
3. Work with Scripts – Positioning JavaScript and CSS
What is the recommended solution!
it’s recommended to place all <script> tags as close to the bottom of the <body> tag as possible so as not to
affect the download of the entire page.
For example:
<html>
<head>
<title>Positioning Scripts</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<p>Good practice!</p>
<script type="text/javascript" src=“//cdnjs.cloudflare.com/js/script_1.js"></script>
<script type="text/javascript" src=“//cdnjs.cloudflare.com/js/script_2.js"></script>
<script type="text/javascript" src=“//cdnjs.cloudflare.com/js/script_3.js"></script>
</body>
</html>
3. Work with Scripts – Group JavaScript and CSS
Downloading one single 100 KB file will be faster than downloading four 25 KB files. Instead of three separate
requests you could do the following and utilize a single request using CDNJS Combo Loader or heeep.it*.
<script type="text/javascript“ src=“//cdnjs.cloudflare.com
?js/script_1.js
&js/script_2.js
&js/script_3.js"></script>
* See more about CDNJS Combo Loader and heeep.it
<script type="text/javascript“
src=“//go.heeep.it?, js/script_1.js, js/script_2.js, js/script_3.js"></script>
CDNJS Combo Loader
heeep.it Loader
3. Work with Scripts – Minify JavaScript and CSS
Minifying is the process of removing unnecessary characters (comments, space, newline and tab) from code. As
a result it reduce file size thereby improving load times.
There are two popular tools for minifying JavaScript code are JSMin and YUI Compressor.
Before:
// is.js
// (c) 2001 Douglas Crockford
// 2001 June 3 // is
// The -is- object is used to identify the browser. Every browser edition
// identifies itself, but there is no standard way of doing it, and some of
// the identification is deceptive. This is because the authors of web
// browsers are liars. For example, Microsoft's IE browsers claim to be
// Mozilla 4. Netscape 6 claims to be version 5.
var is =
{
ie: navigator.appName == 'Microsoft Internet Explorer',
java: navigator.javaEnabled(),
ns: navigator.appName == 'Netscape',
ua: navigator.userAgent.toLowerCase(),
version: parseFloat(navigator.appVersion.substr(21)) || parseFloat(navigator.appVersion),
win: navigator.platform == 'Win32'
}
is.mac = is.ua.indexOf('mac') >= 0;
if (is.ua.indexOf('opera') >= 0)
{
is.ie = is.ns = false;
is.opera = true;
}
if (is.ua.indexOf('gecko') >= 0)
{
is.ie = is.ns = false;
is.gecko = true;
}
After:
var is={ie:navigator.appName=='Microsoft Internet
xplorer',java:navigator.javaEnabled(),ns:navigator.appName=='Netscape',ua:navigator.userAgent.toLowerCase(),version:parseFloat(navigator.appVersion.substr(21))||parseFloat(navigator.appVersion),win:navigator.platform=='Win32'}
is.mac=is.ua.indexOf('mac')>=0;if(is.ua.indexOf('opera')>=0){is.ie=is.ns=false;is.opera=true;} if(is.ua.indexOf('gecko')>=0){is.ie=is.ns=false;is.gecko=true;}
3. Work with Scripts – Compress Content
How we do now (Server without gzip)
Compression is a simple, effective way to save bandwidth and speed up your site.
What is compression?
1. Browser: GET /index.html
2. Server: Ok, let me see if index.html is lying around...
3. Server: Found it! Here's your response code (200 OK) and I'm sending the file.
4. Browser: 100KB? Vay qu ara... waiting, waiting... ok, it's loaded.
3. Work with Scripts – Compress Content
How we should do (Server with gzip)
Compression is a simple, effective way to save bandwidth and speed up your site.
What is compression?
1. Browser: Hey, can I GET index.html? I'll take a compressed version if you've got it.
2. Server: Let me find the file... yep, it's here. And you'll take a compressed version? Awesome.
3. Server: Ok, I've found index.html (200 OK), am zipping it and sending it over.
4. Browser: Great! It's only 10KB. I'll unzip it and show the user.
The formula is simple: Smaller file = faster download = happy user.
3. Work with Scripts – Compress Content
1. Browser: change your .htaccess file
2. Server: For IIS enable compression in the settings
So when a file's too big, just zip it, but how?
Results
This can reduce the size of pages and style sheets by up to 70%!
http://www.whatsmyip.org/http-compression-test/
4. Reduce the Number of DOM Elements
A complex page means more bytes to download and it also means slower DOM access in
JavaScript. It makes a difference if you loop through 500 or 5000 DOM elements on the
page when you want to add an event handler for example.
Overview
What should we do?
A great help with layouts are the YUI CSS utilities: grids.css can help you with the overall
layout, fonts.css and reset.css can help you strip away the browser's defaults formatting.
This is a chance to start fresh and think about your markup, for example use <div>s only
when it makes sense semantically, and not because it renders a new line.
Just type in Firebug's console: document.getElementsByTagName('*').length
How to check you Dom elements number
How many DOM elements should we have on the sigle page
It is tested by Yslow and goes green when count of DOM Element is up to 1800. But there
is no set standard as to how many DOM elements are too many. Check other similar pages
that have good markup. Eg. Yahoo! Home Page is a pretty busy page and still under 700
elements (HTML tags).
5. Develop Smart Event Handlers
Generally we attach event handler to different elements of the DOM tree. Which makes
page dummy because of handlers execution. Instead, the event handler can be added to
one parent. This approach is called Event Delegation.
Overview
How it works?
In DOM tree Events bubble up so you'll be able to catch the event and figure out which
element has fired an event.
<ul id="parent-">
<li id="child-1">Item 1</li>
<li id="child-2">Item 2</li>
<li id="child-3">Item 3</li>
<li id="child-4">Item 4</li>
<li id="child-5">Item 5</li>
<li id="child-6">Item 6</li>
</ul>
Example
<script>
document.getElementById("parent-list").addEventListener("click“, function(e)
{
if(e.target && e.target.nodeName == "LI")
{
console.log("List item ", e.target.id.replace(“child-")," was clicked!");
}
});
</script>
Summary
1. CDN deliver content by choosing server with the quickest response time from
different geographical locations. It will improve end-user response time up to
20%.
2. By using the Expires header you avoid unnecessary HTTP requests on
subsequent page views. Expires headers are most often used with images, but
they should be used on all components including scripts.
3. Make JavaScript and CSS external, minify them and set up GZIP compress
settings. Keep JavaScript on the bottom, CSS on the top. These will improve
your application performance up to 70%.
4. Use tags only when it makes sense semantically, and not because it renders a
new line. Reducing DOM Elements means downloading less bytes and also
higher DOM access in JavaScript.
5. Using Event Delegation is a good approach. You will take advantage of Event
Bubbling and will minimize the use of separate handlers for different
elements. This will reduce execution time and speed up page responsiveness.
References
1. “High Performance JavaScript, by Nicholas C. Zakas. Copyright 2010 Yahoo!,
Inc., 978-0-596-80279-0.”
2. http://developer.yahoo.com/performance/rules.html
3. http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-
compression/
4. http://gtmetrix.com/enable-gzip-compression.html
5. http://www.whatsmyip.org/http-compression-test/
6. https://developers.google.com/speed/articles/gzip
7. http://betterexplained.com/articles/speed-up-your-javascript-load-time/
Author: Arshak Movsisyan
Email: arshak.movsissian@gmail.com

More Related Content

What's hot

Frontend performance
Frontend performanceFrontend performance
Frontend performancesacred 8
 
Week 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuWeek 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuAppUniverz Org
 
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...Distilled
 
Service workers your applications never felt so good
Service workers   your applications never felt so goodService workers   your applications never felt so good
Service workers your applications never felt so goodChris Love
 
What does the browser pre-loader do?
What does the browser pre-loader do?What does the browser pre-loader do?
What does the browser pre-loader do?Andy Davies
 
Html5 Fit: Get Rid of Love Handles
Html5 Fit:  Get Rid of Love HandlesHtml5 Fit:  Get Rid of Love Handles
Html5 Fit: Get Rid of Love HandlesChris Love
 
10 things you can do to speed up your web app today 2016
10 things you can do to speed up your web app today 201610 things you can do to speed up your web app today 2016
10 things you can do to speed up your web app today 2016Chris Love
 
The Case for HTTP/2
The Case for HTTP/2The Case for HTTP/2
The Case for HTTP/2Andy Davies
 
[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web DesignChristopher Schmitt
 
PrairieDevCon 2014 - Web Doesn't Mean Slow
PrairieDevCon 2014 -  Web Doesn't Mean SlowPrairieDevCon 2014 -  Web Doesn't Mean Slow
PrairieDevCon 2014 - Web Doesn't Mean Slowdmethvin
 
Mobile Web Speed Bumps
Mobile Web Speed BumpsMobile Web Speed Bumps
Mobile Web Speed BumpsNicholas Zakas
 
The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014
The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014
The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014Bastian Grimm
 
Optimizing web performance (Fronteers edition)
Optimizing web performance (Fronteers edition)Optimizing web performance (Fronteers edition)
Optimizing web performance (Fronteers edition)Dave Olsen
 
Web Client Performance
Web Client PerformanceWeb Client Performance
Web Client PerformanceHerea Adrian
 
Don't make me wait! or Building High-Performance Web Applications
Don't make me wait! or Building High-Performance Web ApplicationsDon't make me wait! or Building High-Performance Web Applications
Don't make me wait! or Building High-Performance Web ApplicationsStoyan Stefanov
 
Access google command list from the command line
Access google command list from the command lineAccess google command list from the command line
Access google command list from the command lineEthan Lorance
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)Steve Souders
 

What's hot (20)

Frontend performance
Frontend performanceFrontend performance
Frontend performance
 
HTML5
HTML5HTML5
HTML5
 
Week 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuWeek 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. Wu
 
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
SearchLove San Diego 2018 | Tom Anthony | An Introduction to HTTP/2 & Service...
 
Service workers your applications never felt so good
Service workers   your applications never felt so goodService workers   your applications never felt so good
Service workers your applications never felt so good
 
What does the browser pre-loader do?
What does the browser pre-loader do?What does the browser pre-loader do?
What does the browser pre-loader do?
 
Html5 Fit: Get Rid of Love Handles
Html5 Fit:  Get Rid of Love HandlesHtml5 Fit:  Get Rid of Love Handles
Html5 Fit: Get Rid of Love Handles
 
Wordpress as a framework
Wordpress as a frameworkWordpress as a framework
Wordpress as a framework
 
10 things you can do to speed up your web app today 2016
10 things you can do to speed up your web app today 201610 things you can do to speed up your web app today 2016
10 things you can do to speed up your web app today 2016
 
The Case for HTTP/2
The Case for HTTP/2The Case for HTTP/2
The Case for HTTP/2
 
Keep the Web Fast
Keep the Web FastKeep the Web Fast
Keep the Web Fast
 
[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design[jqconatx] Adaptive Images for Responsive Web Design
[jqconatx] Adaptive Images for Responsive Web Design
 
PrairieDevCon 2014 - Web Doesn't Mean Slow
PrairieDevCon 2014 -  Web Doesn't Mean SlowPrairieDevCon 2014 -  Web Doesn't Mean Slow
PrairieDevCon 2014 - Web Doesn't Mean Slow
 
Mobile Web Speed Bumps
Mobile Web Speed BumpsMobile Web Speed Bumps
Mobile Web Speed Bumps
 
The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014
The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014
The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014
 
Optimizing web performance (Fronteers edition)
Optimizing web performance (Fronteers edition)Optimizing web performance (Fronteers edition)
Optimizing web performance (Fronteers edition)
 
Web Client Performance
Web Client PerformanceWeb Client Performance
Web Client Performance
 
Don't make me wait! or Building High-Performance Web Applications
Don't make me wait! or Building High-Performance Web ApplicationsDon't make me wait! or Building High-Performance Web Applications
Don't make me wait! or Building High-Performance Web Applications
 
Access google command list from the command line
Access google command list from the command lineAccess google command list from the command line
Access google command list from the command line
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
 

Viewers also liked

Senior knowledge and belief
Senior knowledge and beliefSenior knowledge and belief
Senior knowledge and beliefSenior Sistemas
 
Social Media for Companies
Social Media for CompaniesSocial Media for Companies
Social Media for CompaniesBlogwerk AG
 
YouGO! Magazine - Pomysły na Wakacje 2013
YouGO! Magazine - Pomysły na Wakacje 2013YouGO! Magazine - Pomysły na Wakacje 2013
YouGO! Magazine - Pomysły na Wakacje 2013YouGO!
 

Viewers also liked (6)

Diversity survived
Diversity survivedDiversity survived
Diversity survived
 
Diversity survived
Diversity survivedDiversity survived
Diversity survived
 
Senior knowledge and belief
Senior knowledge and beliefSenior knowledge and belief
Senior knowledge and belief
 
Social Media for Companies
Social Media for CompaniesSocial Media for Companies
Social Media for Companies
 
YouGO! Magazine - Pomysły na Wakacje 2013
YouGO! Magazine - Pomysły na Wakacje 2013YouGO! Magazine - Pomysły na Wakacje 2013
YouGO! Magazine - Pomysły na Wakacje 2013
 
Workshop 6: Design Game
Workshop 6: Design GameWorkshop 6: Design Game
Workshop 6: Design Game
 

Similar to Building high performance web apps.

DrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizingDrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizingAshok Modi
 
Enough with the javas cript already! de Nicholas Zakas
Enough with the javas cript already! de Nicholas ZakasEnough with the javas cript already! de Nicholas Zakas
Enough with the javas cript already! de Nicholas ZakasKubide
 
Enough with the JavaScript already!
Enough with the JavaScript already!Enough with the JavaScript already!
Enough with the JavaScript already!Nicholas Zakas
 
Drupal Frontend Performance and Scalability
Drupal Frontend Performance and ScalabilityDrupal Frontend Performance and Scalability
Drupal Frontend Performance and ScalabilityAshok Modi
 
Modern Web Technologies
Modern Web TechnologiesModern Web Technologies
Modern Web TechnologiesPerttu Myry
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup PerformanceGreg Whalin
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalabilityTwinbit
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascripttutorialsruby
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascripttutorialsruby
 
Magento Performance Optimization 101
Magento Performance Optimization 101Magento Performance Optimization 101
Magento Performance Optimization 101Angus Li
 
Drupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthDrupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthPhilip Norton
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...tdc-globalcode
 
The Need for Speed - SMX Sydney 2013
The Need for Speed - SMX Sydney 2013The Need for Speed - SMX Sydney 2013
The Need for Speed - SMX Sydney 2013Bastian Grimm
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal PerformancesVladimir Ilic
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083Divyam Pateriya
 

Similar to Building high performance web apps. (20)

DrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizingDrupalCampLA 2011 - Drupal frontend-optimizing
DrupalCampLA 2011 - Drupal frontend-optimizing
 
Enough with the javas cript already! de Nicholas Zakas
Enough with the javas cript already! de Nicholas ZakasEnough with the javas cript already! de Nicholas Zakas
Enough with the javas cript already! de Nicholas Zakas
 
Enough with the JavaScript already!
Enough with the JavaScript already!Enough with the JavaScript already!
Enough with the JavaScript already!
 
Drupal Frontend Performance and Scalability
Drupal Frontend Performance and ScalabilityDrupal Frontend Performance and Scalability
Drupal Frontend Performance and Scalability
 
Modern Web Technologies
Modern Web TechnologiesModern Web Technologies
Modern Web Technologies
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalability
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascript
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascript
 
Magento Performance Optimization 101
Magento Performance Optimization 101Magento Performance Optimization 101
Magento Performance Optimization 101
 
Drupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp NorthDrupal Performance : DrupalCamp North
Drupal Performance : DrupalCamp North
 
Webpack
Webpack Webpack
Webpack
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
 
Taking your Web App for a walk
Taking your Web App for a walkTaking your Web App for a walk
Taking your Web App for a walk
 
Web technologies part-2
Web technologies part-2Web technologies part-2
Web technologies part-2
 
The Need for Speed - SMX Sydney 2013
The Need for Speed - SMX Sydney 2013The Need for Speed - SMX Sydney 2013
The Need for Speed - SMX Sydney 2013
 
Html5 & less css
Html5 & less cssHtml5 & less css
Html5 & less css
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal Performances
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
 

Recently uploaded

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Recently uploaded (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

Building high performance web apps.

  • 1. Building High Performance Web Apps. Essential rules and common practice Author: Arshak Movsisyan Email: arshak.movsissian@gmail.com
  • 2. 5 Rules For High Performance 1. Use a Content Delivery Network (CDN) 2. Add an Expires or a Cache-Control Header 3. Work with Scripts (Make External, Position, Group, Minify, Compress) 4. Reduce the Number of DOM Elements 5. Develop Smart Event Handlers
  • 3. 1. Use a CDN What is CDN? CDN is a collection of web servers distributed across multiple locations to deliver content more efficiently to users. E.g. CloudFlare, Coral Content Distribution Network, Incapsula, etc. How CDN works? The server with the fewest network hops or the server with the quickest response time is chosen. Results Researches showed that it improves end-user response times by 20% or more, meanwhile 80-90% of the end-user response time is spent downloading all the components in the page: images, stylesheets, scripts, etc.
  • 4. 2. Add an Expires or a Cache-Control Header For static components: implement "Never expire" policy by setting far future Expires header. Example: Expires: Thu, 15 Apr 2020 20:00:00 GMT But keep in mind, if you use a far future Expires header you have to change the component's filename whenever the component changes. For dynamic components: use an appropriate Cache-Control header to help the browser with conditional requests <FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> Header set Cache-Control "max-age=290304000, public" </FilesMatch> This goes in your root .htaccess file but if you have access to httpd.conf that is better.
  • 5. 3. Work with Scripts - Make JavaScript and CSS External Why making scripts external is faster? Using external files generally produces faster pages because the JavaScript and CSS files are cached by the browser. Results External files are cached by the browser, the size of the HTML document is reduced without increasing the number of HTTP requests.
  • 6. 3. Work with Scripts – Positioning JavaScript and CSS How do we generally position scripts? <html> <head> <title>Positioning Scripts</title> <link rel="stylesheet" type="text/css" href="style.css"> <script type="text/javascript" src=“//cdnjs.cloudflare.com/js/script_1.js"></script> <script type="text/javascript" src=“//cdnjs.cloudflare.com/js/script_2.js"></script> <script type="text/javascript" src=“//cdnjs.cloudflare.com/js/script_3.js"></script> </head> <body> <p>Not a good practice!</p> </body> </html>
  • 7. 3. Work with Scripts – Positioning JavaScript and CSS Code Execution Flow Each file must wait until the previous one has been downloaded and executed before the next download can begin. In the meantime, the user is met with a blank screen as the files are being downloaded one at a time. This is the behavior of most major browsers today. How it works.
  • 8. 3. Work with Scripts – Positioning JavaScript and CSS What is the recommended solution! it’s recommended to place all <script> tags as close to the bottom of the <body> tag as possible so as not to affect the download of the entire page. For example: <html> <head> <title>Positioning Scripts</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <p>Good practice!</p> <script type="text/javascript" src=“//cdnjs.cloudflare.com/js/script_1.js"></script> <script type="text/javascript" src=“//cdnjs.cloudflare.com/js/script_2.js"></script> <script type="text/javascript" src=“//cdnjs.cloudflare.com/js/script_3.js"></script> </body> </html>
  • 9. 3. Work with Scripts – Group JavaScript and CSS Downloading one single 100 KB file will be faster than downloading four 25 KB files. Instead of three separate requests you could do the following and utilize a single request using CDNJS Combo Loader or heeep.it*. <script type="text/javascript“ src=“//cdnjs.cloudflare.com ?js/script_1.js &js/script_2.js &js/script_3.js"></script> * See more about CDNJS Combo Loader and heeep.it <script type="text/javascript“ src=“//go.heeep.it?, js/script_1.js, js/script_2.js, js/script_3.js"></script> CDNJS Combo Loader heeep.it Loader
  • 10. 3. Work with Scripts – Minify JavaScript and CSS Minifying is the process of removing unnecessary characters (comments, space, newline and tab) from code. As a result it reduce file size thereby improving load times. There are two popular tools for minifying JavaScript code are JSMin and YUI Compressor. Before: // is.js // (c) 2001 Douglas Crockford // 2001 June 3 // is // The -is- object is used to identify the browser. Every browser edition // identifies itself, but there is no standard way of doing it, and some of // the identification is deceptive. This is because the authors of web // browsers are liars. For example, Microsoft's IE browsers claim to be // Mozilla 4. Netscape 6 claims to be version 5. var is = { ie: navigator.appName == 'Microsoft Internet Explorer', java: navigator.javaEnabled(), ns: navigator.appName == 'Netscape', ua: navigator.userAgent.toLowerCase(), version: parseFloat(navigator.appVersion.substr(21)) || parseFloat(navigator.appVersion), win: navigator.platform == 'Win32' } is.mac = is.ua.indexOf('mac') >= 0; if (is.ua.indexOf('opera') >= 0) { is.ie = is.ns = false; is.opera = true; } if (is.ua.indexOf('gecko') >= 0) { is.ie = is.ns = false; is.gecko = true; } After: var is={ie:navigator.appName=='Microsoft Internet xplorer',java:navigator.javaEnabled(),ns:navigator.appName=='Netscape',ua:navigator.userAgent.toLowerCase(),version:parseFloat(navigator.appVersion.substr(21))||parseFloat(navigator.appVersion),win:navigator.platform=='Win32'} is.mac=is.ua.indexOf('mac')>=0;if(is.ua.indexOf('opera')>=0){is.ie=is.ns=false;is.opera=true;} if(is.ua.indexOf('gecko')>=0){is.ie=is.ns=false;is.gecko=true;}
  • 11. 3. Work with Scripts – Compress Content How we do now (Server without gzip) Compression is a simple, effective way to save bandwidth and speed up your site. What is compression? 1. Browser: GET /index.html 2. Server: Ok, let me see if index.html is lying around... 3. Server: Found it! Here's your response code (200 OK) and I'm sending the file. 4. Browser: 100KB? Vay qu ara... waiting, waiting... ok, it's loaded.
  • 12. 3. Work with Scripts – Compress Content How we should do (Server with gzip) Compression is a simple, effective way to save bandwidth and speed up your site. What is compression? 1. Browser: Hey, can I GET index.html? I'll take a compressed version if you've got it. 2. Server: Let me find the file... yep, it's here. And you'll take a compressed version? Awesome. 3. Server: Ok, I've found index.html (200 OK), am zipping it and sending it over. 4. Browser: Great! It's only 10KB. I'll unzip it and show the user. The formula is simple: Smaller file = faster download = happy user.
  • 13. 3. Work with Scripts – Compress Content 1. Browser: change your .htaccess file 2. Server: For IIS enable compression in the settings So when a file's too big, just zip it, but how? Results This can reduce the size of pages and style sheets by up to 70%! http://www.whatsmyip.org/http-compression-test/
  • 14. 4. Reduce the Number of DOM Elements A complex page means more bytes to download and it also means slower DOM access in JavaScript. It makes a difference if you loop through 500 or 5000 DOM elements on the page when you want to add an event handler for example. Overview What should we do? A great help with layouts are the YUI CSS utilities: grids.css can help you with the overall layout, fonts.css and reset.css can help you strip away the browser's defaults formatting. This is a chance to start fresh and think about your markup, for example use <div>s only when it makes sense semantically, and not because it renders a new line. Just type in Firebug's console: document.getElementsByTagName('*').length How to check you Dom elements number How many DOM elements should we have on the sigle page It is tested by Yslow and goes green when count of DOM Element is up to 1800. But there is no set standard as to how many DOM elements are too many. Check other similar pages that have good markup. Eg. Yahoo! Home Page is a pretty busy page and still under 700 elements (HTML tags).
  • 15. 5. Develop Smart Event Handlers Generally we attach event handler to different elements of the DOM tree. Which makes page dummy because of handlers execution. Instead, the event handler can be added to one parent. This approach is called Event Delegation. Overview How it works? In DOM tree Events bubble up so you'll be able to catch the event and figure out which element has fired an event. <ul id="parent-"> <li id="child-1">Item 1</li> <li id="child-2">Item 2</li> <li id="child-3">Item 3</li> <li id="child-4">Item 4</li> <li id="child-5">Item 5</li> <li id="child-6">Item 6</li> </ul> Example <script> document.getElementById("parent-list").addEventListener("click“, function(e) { if(e.target && e.target.nodeName == "LI") { console.log("List item ", e.target.id.replace(“child-")," was clicked!"); } }); </script>
  • 16. Summary 1. CDN deliver content by choosing server with the quickest response time from different geographical locations. It will improve end-user response time up to 20%. 2. By using the Expires header you avoid unnecessary HTTP requests on subsequent page views. Expires headers are most often used with images, but they should be used on all components including scripts. 3. Make JavaScript and CSS external, minify them and set up GZIP compress settings. Keep JavaScript on the bottom, CSS on the top. These will improve your application performance up to 70%. 4. Use tags only when it makes sense semantically, and not because it renders a new line. Reducing DOM Elements means downloading less bytes and also higher DOM access in JavaScript. 5. Using Event Delegation is a good approach. You will take advantage of Event Bubbling and will minimize the use of separate handlers for different elements. This will reduce execution time and speed up page responsiveness.
  • 17. References 1. “High Performance JavaScript, by Nicholas C. Zakas. Copyright 2010 Yahoo!, Inc., 978-0-596-80279-0.” 2. http://developer.yahoo.com/performance/rules.html 3. http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip- compression/ 4. http://gtmetrix.com/enable-gzip-compression.html 5. http://www.whatsmyip.org/http-compression-test/ 6. https://developers.google.com/speed/articles/gzip 7. http://betterexplained.com/articles/speed-up-your-javascript-load-time/ Author: Arshak Movsisyan Email: arshak.movsissian@gmail.com