SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Presentation Tier
                   Optimizations
                      Optimization of Web UI layer
                                      Presentation By
                                      Anup Hariharan Nair
                                      Date: 16 April 2011
                                      http://HiFiCoding.com/




Prepared using :
Why bother ?


 Google found that the page with 10 results took 0.4 seconds to
  generate. The page with 30 results took 0.9 seconds. Half a
  second delay caused a 20% drop in traffic. Half a second delay
  killed user satisfaction.

 In A/B tests, Amazon tried delaying the page in increments of 100
  milliseconds and found that even very small delays would result
  in substantial and costly drops in revenue.

 Reference :
  http://www.codinghorror.com/blog/2011/06/performance-is-a-
  feature.html
Focus of Web Optimization


 Organizations focus process optimization of
    Data Tier
    Application Tier


    Presentation Tier is usually ignored.
    Presentation Tier is responsible for more than 30% of Client/Server
     application performance


 Who is to be blamed?
    In early days, there were no articles on patterns or engineering practices to
     optimize the Presentation Tier.
    Still need specialists to
    Understand the loading pattern of HTTP-Response objects.
    Optimize the Load pattern of HTTP-Response objects.
What should be
                                                considered?
 Optimizing Presentation Tier requires an engineering approach.

 Two most important aspects of optimizing the presentation Tier
  are
    Reduce HTTP Requests
      • Reducing the total number of HTTP Requests made to the server by the
         Clients browser.
    Optimize HTTP Response Objects
      • Reduce the total HTTP Response objects sent from server to client.
      • Reduce the size of response objects.
      • Re-Engineer the load pattern for response objects.
What should be
                                           considered?
 Total size of data to be loaded on HTTP calls. (Minify Html, CSS
  and JavaScript to reduce size of response objects)

 Time it takes for the browser to read (Parse) the mark-up
  language, and client side scripts. (W3C compliant mark-up are
  rendered quickly by the Web-Browser.)

 Number and size of the multimedia contents like
  video, photo, and flash.

 HTTP server Caching of repeated object requests.

 Number of Content Delivery Networks (CDN) available from the
  point of HTTP request.
JavaScript Development
                                        Patterns
 Load JavaScript On-Demand.

 Compress Your JavaScript (minify files)

 Place JavaScript at end of Mark-up.
Load JavaScript
                                                                           On-Demand.
<script type='text/javascript' src='snip.js'></script>
                                                          Vs.
If(event ==“true”)
{
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'snip.js'; /*Only import the Library on the occurrence of an event.*/
document.getElementsByTagName('head')[0].appendChild(script);
}



/* import with a random query parameter to avoid caching */
       function $importNoCache(src){
         var ms = new Date().getTime().toString();
         var seed = "?" + ms;
         $import(src + seed);
       }
Compress (minify)
                                               JavaScript
 Analyze your code and make sure it is well-formatted.

 Compress your JavaScript.
    Remove spaces, comments and shorten variable names where appropriate.
    We should pack the original JavaScript and deploy the packed version to
     website.


 Standard Naming Convention : “.min” in file name
 usually a prefix just before the extension.
Minify JavaScript

Before Minifying:
function todaydate()
{
     /*Variable declaration*/
     var today_date= new Date();
     var myyear=today_date.getYear();
     var mymonth=today_date.getMonth()+1        /*No semicolon, but will work */
     var mytoday=today_date.getDate();

     /*Action*/
     document.write(myyear+"/"+mymonth+"/"+mytoday)
}
--------------------------------------------------------------------------------------------------------------
After Minifying:
function todaydate(){var today_date= new Date(); var myyear=today_date.getYear();var mymonth
     =today_date.getMonth()+1; var mytoday=today_date.getDate();
     document.write(myyear+"/"+mymonth+"/"+mytoday)}
-----------------------------------------------------------------------------------------------------------------
Standard Naming Convention Sample :
     jquery-1.6.2.js (Source version or Developer version)
     jquery-1.6.2.min.js (Minified version or Deployment Version)
Place your JavaScript at
                             the end of your HTML.
 Place your JavaScript at the end of your HTML file if possible.
 Notice how Google analytics and other statistics tracking software
  wants to be right before the closing </body> tag.
 This allows the majority of page content (like images, tables, text)
  to be loaded and rendered first by the Parser.
 The user sees content loading, so the page looks responsive.
 At this point, the heavy JavaScript's can begin loading near the
  end.
 Online SEO : Google/MSN/Yahoo AI crawling Bots also prefer
  this pattern.
 Search Engine Crawlers only index Mark-up.
 They do not index Client Side Scripts.
Place your JavaScript at
                                          the end of your HTML.
Sample
   <html>
   <head></head>
   <body>

   <!--Some Body Code-->
   <button type="button" onclick="displayDate()">Display Date</button>
   <!--Some Body Code-->

   <script type="text/javascript">
          function displayDate()
          {document.getElementById("demo").innerHTML=Date();}
   </script>
   <script src="myjs.js"></script>
   </body>
   </html>
Load Media On-Demand


 Yahoo.com loads images when they are in browsers viewable
  zone.

 jQuery-Images-OnDemand Library.
    http://code.google.com/p/jquery-images-ondemand/
    Library takes care of most of the operation.
    All that is needed is to append an additional CSS Class to the “img” object as
     follows :

        <img class=„class1 img-ondemand' longdesc='my_pic.jpg' src='pix.gif' />


    This is a very simple script to load images On-Demand.
    Using this you avoid to load all page images and get a faster web page. Also
     adds delayed load of Image objects.
    With HTML5, Multimedia objects can also be extracted using jQuery or
     DOM, as they can be specified by Tags instead of embedding using an
     OBJECT Tag.
CSS Sprites


 To reduce the number of requests the browser makes to the
  server, some web designers combine numerous small images or
  icons into a larger image called a sprite sheet or tile set.

 CSS is used to select the parts of the composite image to display
  at different points in the page. If a page has ten 1 kB images, they
  can be combined into one 10 kB image, downloaded with a single
  HTTP request, and then positioned with CSS.

 Reducing the number of HTTP requests can make a Web page
  load much faster. In this usage, the sprite sheet format that had
  been developed for use in game and animation engines is being
  applied to static images
Before CSS Sprite


 CSS Code :
      /* Three different images.*/
      #item1 a:hover{background: url('img_1.gif')}
      #item2 a:hover{background: url('img_2.gif') }
      #item3 a:hover{background: url('img_3.gif') }



 HTML/XHTML Code :
      <div id=“item1”> </div> <!—This will show the first image-->
      <div id=“item2”> </div> <!—This will show the second image-->
      <div id=“item3”> </div> <!—This will show the third image-->
After CSS Sprite


 CSS Code :
      /*One image. Parts of the image are referenced.*/
      #item1 a:hover{background: url('img_sprites.gif') 0 -45px;}
      #item2 a:hover{background: url('img_sprites.gif') -47px -45px;}
      #item3 a:hover{background: url('img_sprites.gif') -91px -45px;}



 HTML/XHTML Code :
      <div id=“item1”> </div> <!—This will show the first image-->
      <div id=“item2”> </div> <!—This will show the second image-->
      <div id=“item3”> </div> <!—This will show the third image-->
CSS Sprites – Merged
                                             Image
 Arranging the images in the sprite   Horizontal Merge
  horizontally as opposed to
  vertically usually results in a
  smaller file size.

 Combining similar colors in a
  sprite helps you keep the color
  count low, ideally under 256
  colors so to fit in a PNG8.

                                         Vertical Merge
HTTP Cache


 Oldest trick of the trade
HTTP Caching –
                                            ETag (Entity tags)
 Comparing versions with the modification time generally works, but could lead
  to problems.
 What if the server‟s clock was originally wrong and then got fixed?
 What if daylight savings time comes early and the server isn‟t updated?
 The caches could be inaccurate.

 ETags to the rescue. An ETag is a unique identifier given to every file. It‟s like
  a hash or fingerprint: every file gets a unique fingerprint, and if you change
  the file (even by one byte), the fingerprint changes as well.

 Instead of sending back the modification time, the server can send back the
  ETag (fingerprint):
 Etag example : ead145f
 File Contents could be an image, HTML, CSS, JavaScript..)

 The ETag can be any string which uniquely identifies the file. The next time
  the browser needs logo.png, it can have a conversation like this
HTTP Caching –
                 ETag (Entity tags)
 Etag Caching
CDN


 A content delivery network or content distribution network (CDN)
  is a system of computers containing copies of data, placed at
  various points in a network so as to maximize bandwidth for
  access to the data from clients throughout the network.

 A client accesses a copy of the data near to the client, as
  opposed to all clients accessing the same central server, so as to
  avoid bottlenecks near that server.

 Content types include web objects, downloadable objects (media
  files, software, documents), applications, real time media
  streams, and other components of internet delivery
  (DNS, routes, and database queries).
 Not Replicated Servers.
Commercial CDN


   Akamai Technologies
   Amazon CloudFront
   AT&T
   Bitgravity
   CDNetworks
   Chinacache
   Cotendo
   EdgeCast Networks
   Highwinds Network Group
   Internap
   Level 3 Communications
   Limelight Networks
   Microsoft Windows Azure CDN
   Mirror Image Internet
   NetDNA
Runtime – HTTP
                                               Compressions
 Runtime HTTP Compressions




   Configuring HTTP Compression in IIS
      http://technet.microsoft.com/en-us/library/cc771003%28WS.10%29.aspx
      Note : It is not enabled by default.
   Configuring HTTP GZIP Compression in APACHE
      http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-
         compression/
      Note : Need to install GZIP modules and configure with Apache.
Valid W3C compliant page


 http://validator.w3.org/

 Not just for cross browser rendering & validation.

 Helps browsers to quickly read the documents & render it without
  getting confused. This avoid a delay in page processing at clients
  browser.
How do I test my
                          Application Performance?
 Online Test (Online Testing)
    WebPageTest.ORG from AOL.
        • URL : http://www.webpagetest.org
    It provides :
        • Waterfall Load Pattern
        • HTTP Response Object Load Pattern and time.
        • Optimization Checklist.
 Test on Workstation (Offline Testing)
    YSlow plug-in for Firebug in Firefox, from Yahoo Developer Network.
    URL : http://developer.yahoo.com/yslow/
      • Does not provide Waterfall Load Pattern
      • Only provides Optimization Checklist.
Reference


 Yahoo Client/Server Developer reference
    http://developer.yahoo.com/performance/rules.html
 Google Client/Server Developer reference
    http://code.google.com/speed/page-speed/docs/rules_intro.html
 W3C standards compliant Web sites
    http://www.w3.org/QA/2002/07/WebAgency-Requirements

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Deploying Cloud Use Cases
Deploying Cloud Use CasesDeploying Cloud Use Cases
Deploying Cloud Use Cases
 
TugaIT 2016 - Docker and the world of “containerized" environments​
TugaIT 2016 - Docker and the world of “containerized" environments​TugaIT 2016 - Docker and the world of “containerized" environments​
TugaIT 2016 - Docker and the world of “containerized" environments​
 
Lets talk about: Azure Kubernetes Service (AKS)
Lets talk about: Azure Kubernetes Service (AKS)Lets talk about: Azure Kubernetes Service (AKS)
Lets talk about: Azure Kubernetes Service (AKS)
 
Container orchestration k8s azure kubernetes services
Container orchestration  k8s azure kubernetes servicesContainer orchestration  k8s azure kubernetes services
Container orchestration k8s azure kubernetes services
 
Azure Container Services​
Azure Container Services​Azure Container Services​
Azure Container Services​
 
Azure Container Services​
Azure Container Services​Azure Container Services​
Azure Container Services​
 
ContainerDays NYC 2016: "Containers in Azure: Understanding the Microsoft Con...
ContainerDays NYC 2016: "Containers in Azure: Understanding the Microsoft Con...ContainerDays NYC 2016: "Containers in Azure: Understanding the Microsoft Con...
ContainerDays NYC 2016: "Containers in Azure: Understanding the Microsoft Con...
 
Comparison and mapping between various cloud services 2019
Comparison and mapping between various cloud services 2019Comparison and mapping between various cloud services 2019
Comparison and mapping between various cloud services 2019
 
Tooling and DevOps for the Hybrid Cloud with Azure and Azure Stack
Tooling and DevOps for the Hybrid Cloud with Azure and Azure StackTooling and DevOps for the Hybrid Cloud with Azure and Azure Stack
Tooling and DevOps for the Hybrid Cloud with Azure and Azure Stack
 
Azure vidyapeeth -Introduction to Azure Container Service & Registry Service
Azure vidyapeeth -Introduction to Azure Container Service & Registry ServiceAzure vidyapeeth -Introduction to Azure Container Service & Registry Service
Azure vidyapeeth -Introduction to Azure Container Service & Registry Service
 
Azure fundamentals 03
Azure fundamentals 03Azure fundamentals 03
Azure fundamentals 03
 
Azure Automation and Update Management
Azure Automation and Update ManagementAzure Automation and Update Management
Azure Automation and Update Management
 
Microsoft Azure News - 2018 June
Microsoft Azure News - 2018 JuneMicrosoft Azure News - 2018 June
Microsoft Azure News - 2018 June
 
Monitor Cloud Resources using Alerts & Insights
Monitor Cloud Resources using Alerts & InsightsMonitor Cloud Resources using Alerts & Insights
Monitor Cloud Resources using Alerts & Insights
 
Debugging and Interacting with Production Applications - MS Online Tech Forum
Debugging and Interacting with Production Applications - MS Online Tech ForumDebugging and Interacting with Production Applications - MS Online Tech Forum
Debugging and Interacting with Production Applications - MS Online Tech Forum
 
04_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
04_Azure Kubernetes Service: Basic Practices for Developers_GAB201904_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
04_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
 
Innovation anywhere with microsoft azure arc
Innovation anywhere with microsoft azure arcInnovation anywhere with microsoft azure arc
Innovation anywhere with microsoft azure arc
 
Architecting and Building Hybrid Cloud Apps for Azure and Azure Stack
Architecting and Building Hybrid Cloud Apps for Azure and Azure StackArchitecting and Building Hybrid Cloud Apps for Azure and Azure Stack
Architecting and Building Hybrid Cloud Apps for Azure and Azure Stack
 
TechnoramaNL Azure Key Vault, Azure Dev Ops and Azure Data Factor
TechnoramaNL Azure Key Vault, Azure Dev Ops and Azure Data FactorTechnoramaNL Azure Key Vault, Azure Dev Ops and Azure Data Factor
TechnoramaNL Azure Key Vault, Azure Dev Ops and Azure Data Factor
 
Intro to docker and kubernetes
Intro to docker and kubernetesIntro to docker and kubernetes
Intro to docker and kubernetes
 

Andere mochten auch

Java vs .net
Java vs .netJava vs .net
Java vs .net
Tech_MX
 

Andere mochten auch (7)

Presemtation Tier Optimizations
Presemtation Tier OptimizationsPresemtation Tier Optimizations
Presemtation Tier Optimizations
 
Age of Quantum computing
Age of Quantum computingAge of Quantum computing
Age of Quantum computing
 
Integrated ALM using Microsoft 2012 Solutions
Integrated ALM using Microsoft 2012 SolutionsIntegrated ALM using Microsoft 2012 Solutions
Integrated ALM using Microsoft 2012 Solutions
 
Java vs .net
Java vs .netJava vs .net
Java vs .net
 
Comparison of Programming Platforms
Comparison of Programming PlatformsComparison of Programming Platforms
Comparison of Programming Platforms
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
 
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job? Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
 

Ähnlich wie Presentation Tier optimizations

[convergese] Adaptive Images in Responsive Web Design
[convergese] Adaptive Images in Responsive Web Design[convergese] Adaptive Images in Responsive Web Design
[convergese] Adaptive Images in Responsive Web Design
Christopher Schmitt
 
Front end optimization
Front end optimizationFront end optimization
Front end optimization
Abhishek Anand
 
Optimising Web Application Frontend
Optimising Web Application FrontendOptimising Web Application Frontend
Optimising Web Application Frontend
tkramar
 
[rwdsummit2012] Adaptive Images in Responsive Web Design
[rwdsummit2012] Adaptive Images in Responsive Web Design[rwdsummit2012] Adaptive Images in Responsive Web Design
[rwdsummit2012] Adaptive Images in Responsive Web Design
Christopher Schmitt
 
[cssdevconf] Adaptive Images in RWD
[cssdevconf] Adaptive Images in RWD[cssdevconf] Adaptive Images in RWD
[cssdevconf] Adaptive Images in RWD
Christopher Schmitt
 

Ähnlich wie Presentation Tier optimizations (20)

Building high performing web pages
Building high performing web pagesBuilding high performing web pages
Building high performing web pages
 
Html5
Html5Html5
Html5
 
[convergese] Adaptive Images in Responsive Web Design
[convergese] Adaptive Images in Responsive Web Design[convergese] Adaptive Images in Responsive Web Design
[convergese] Adaptive Images in Responsive Web Design
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
 
Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web Apps
 
Exploring Critical Rendering Path
Exploring Critical Rendering PathExploring Critical Rendering Path
Exploring Critical Rendering Path
 
Note of CGI and ASP
Note of CGI and ASPNote of CGI and ASP
Note of CGI and ASP
 
Frontend performance
Frontend performanceFrontend performance
Frontend performance
 
Front end optimization
Front end optimizationFront end optimization
Front end optimization
 
Optimising Web Application Frontend
Optimising Web Application FrontendOptimising Web Application Frontend
Optimising Web Application Frontend
 
Sanjeev ghai 12
Sanjeev ghai 12Sanjeev ghai 12
Sanjeev ghai 12
 
Javascript Bundling and modularization
Javascript Bundling and modularizationJavascript Bundling and modularization
Javascript Bundling and modularization
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
Meetup Performance
Meetup PerformanceMeetup Performance
Meetup Performance
 
Web Components: back to the future
Web Components: back to the futureWeb Components: back to the future
Web Components: back to the future
 
[rwdsummit2012] Adaptive Images in Responsive Web Design
[rwdsummit2012] Adaptive Images in Responsive Web Design[rwdsummit2012] Adaptive Images in Responsive Web Design
[rwdsummit2012] Adaptive Images in Responsive Web Design
 
Tips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC ApplicationsTips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC Applications
 
[cssdevconf] Adaptive Images in RWD
[cssdevconf] Adaptive Images in RWD[cssdevconf] Adaptive Images in RWD
[cssdevconf] Adaptive Images in RWD
 
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考えるIt is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
 
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
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

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)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
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...
 
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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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...
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
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
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.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
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 

Presentation Tier optimizations

  • 1. Presentation Tier Optimizations Optimization of Web UI layer Presentation By Anup Hariharan Nair Date: 16 April 2011 http://HiFiCoding.com/ Prepared using :
  • 2. Why bother ?  Google found that the page with 10 results took 0.4 seconds to generate. The page with 30 results took 0.9 seconds. Half a second delay caused a 20% drop in traffic. Half a second delay killed user satisfaction.  In A/B tests, Amazon tried delaying the page in increments of 100 milliseconds and found that even very small delays would result in substantial and costly drops in revenue.  Reference : http://www.codinghorror.com/blog/2011/06/performance-is-a- feature.html
  • 3. Focus of Web Optimization  Organizations focus process optimization of  Data Tier  Application Tier  Presentation Tier is usually ignored.  Presentation Tier is responsible for more than 30% of Client/Server application performance  Who is to be blamed?  In early days, there were no articles on patterns or engineering practices to optimize the Presentation Tier.  Still need specialists to  Understand the loading pattern of HTTP-Response objects.  Optimize the Load pattern of HTTP-Response objects.
  • 4. What should be considered?  Optimizing Presentation Tier requires an engineering approach.  Two most important aspects of optimizing the presentation Tier are  Reduce HTTP Requests • Reducing the total number of HTTP Requests made to the server by the Clients browser.  Optimize HTTP Response Objects • Reduce the total HTTP Response objects sent from server to client. • Reduce the size of response objects. • Re-Engineer the load pattern for response objects.
  • 5. What should be considered?  Total size of data to be loaded on HTTP calls. (Minify Html, CSS and JavaScript to reduce size of response objects)  Time it takes for the browser to read (Parse) the mark-up language, and client side scripts. (W3C compliant mark-up are rendered quickly by the Web-Browser.)  Number and size of the multimedia contents like video, photo, and flash.  HTTP server Caching of repeated object requests.  Number of Content Delivery Networks (CDN) available from the point of HTTP request.
  • 6. JavaScript Development Patterns  Load JavaScript On-Demand.  Compress Your JavaScript (minify files)  Place JavaScript at end of Mark-up.
  • 7. Load JavaScript On-Demand. <script type='text/javascript' src='snip.js'></script> Vs. If(event ==“true”) { var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'snip.js'; /*Only import the Library on the occurrence of an event.*/ document.getElementsByTagName('head')[0].appendChild(script); } /* import with a random query parameter to avoid caching */ function $importNoCache(src){ var ms = new Date().getTime().toString(); var seed = "?" + ms; $import(src + seed); }
  • 8. Compress (minify) JavaScript  Analyze your code and make sure it is well-formatted.  Compress your JavaScript.  Remove spaces, comments and shorten variable names where appropriate.  We should pack the original JavaScript and deploy the packed version to website.  Standard Naming Convention : “.min” in file name  usually a prefix just before the extension.
  • 9. Minify JavaScript Before Minifying: function todaydate() { /*Variable declaration*/ var today_date= new Date(); var myyear=today_date.getYear(); var mymonth=today_date.getMonth()+1 /*No semicolon, but will work */ var mytoday=today_date.getDate(); /*Action*/ document.write(myyear+"/"+mymonth+"/"+mytoday) } -------------------------------------------------------------------------------------------------------------- After Minifying: function todaydate(){var today_date= new Date(); var myyear=today_date.getYear();var mymonth =today_date.getMonth()+1; var mytoday=today_date.getDate(); document.write(myyear+"/"+mymonth+"/"+mytoday)} ----------------------------------------------------------------------------------------------------------------- Standard Naming Convention Sample : jquery-1.6.2.js (Source version or Developer version) jquery-1.6.2.min.js (Minified version or Deployment Version)
  • 10. Place your JavaScript at the end of your HTML.  Place your JavaScript at the end of your HTML file if possible.  Notice how Google analytics and other statistics tracking software wants to be right before the closing </body> tag.  This allows the majority of page content (like images, tables, text) to be loaded and rendered first by the Parser.  The user sees content loading, so the page looks responsive.  At this point, the heavy JavaScript's can begin loading near the end.  Online SEO : Google/MSN/Yahoo AI crawling Bots also prefer this pattern.  Search Engine Crawlers only index Mark-up.  They do not index Client Side Scripts.
  • 11. Place your JavaScript at the end of your HTML. Sample <html> <head></head> <body> <!--Some Body Code--> <button type="button" onclick="displayDate()">Display Date</button> <!--Some Body Code--> <script type="text/javascript"> function displayDate() {document.getElementById("demo").innerHTML=Date();} </script> <script src="myjs.js"></script> </body> </html>
  • 12. Load Media On-Demand  Yahoo.com loads images when they are in browsers viewable zone.  jQuery-Images-OnDemand Library.  http://code.google.com/p/jquery-images-ondemand/  Library takes care of most of the operation.  All that is needed is to append an additional CSS Class to the “img” object as follows : <img class=„class1 img-ondemand' longdesc='my_pic.jpg' src='pix.gif' />  This is a very simple script to load images On-Demand.  Using this you avoid to load all page images and get a faster web page. Also adds delayed load of Image objects.  With HTML5, Multimedia objects can also be extracted using jQuery or DOM, as they can be specified by Tags instead of embedding using an OBJECT Tag.
  • 13. CSS Sprites  To reduce the number of requests the browser makes to the server, some web designers combine numerous small images or icons into a larger image called a sprite sheet or tile set.  CSS is used to select the parts of the composite image to display at different points in the page. If a page has ten 1 kB images, they can be combined into one 10 kB image, downloaded with a single HTTP request, and then positioned with CSS.  Reducing the number of HTTP requests can make a Web page load much faster. In this usage, the sprite sheet format that had been developed for use in game and animation engines is being applied to static images
  • 14. Before CSS Sprite  CSS Code : /* Three different images.*/ #item1 a:hover{background: url('img_1.gif')} #item2 a:hover{background: url('img_2.gif') } #item3 a:hover{background: url('img_3.gif') }  HTML/XHTML Code : <div id=“item1”> </div> <!—This will show the first image--> <div id=“item2”> </div> <!—This will show the second image--> <div id=“item3”> </div> <!—This will show the third image-->
  • 15. After CSS Sprite  CSS Code : /*One image. Parts of the image are referenced.*/ #item1 a:hover{background: url('img_sprites.gif') 0 -45px;} #item2 a:hover{background: url('img_sprites.gif') -47px -45px;} #item3 a:hover{background: url('img_sprites.gif') -91px -45px;}  HTML/XHTML Code : <div id=“item1”> </div> <!—This will show the first image--> <div id=“item2”> </div> <!—This will show the second image--> <div id=“item3”> </div> <!—This will show the third image-->
  • 16. CSS Sprites – Merged Image  Arranging the images in the sprite Horizontal Merge horizontally as opposed to vertically usually results in a smaller file size.  Combining similar colors in a sprite helps you keep the color count low, ideally under 256 colors so to fit in a PNG8. Vertical Merge
  • 17. HTTP Cache  Oldest trick of the trade
  • 18. HTTP Caching – ETag (Entity tags)  Comparing versions with the modification time generally works, but could lead to problems.  What if the server‟s clock was originally wrong and then got fixed?  What if daylight savings time comes early and the server isn‟t updated?  The caches could be inaccurate.  ETags to the rescue. An ETag is a unique identifier given to every file. It‟s like a hash or fingerprint: every file gets a unique fingerprint, and if you change the file (even by one byte), the fingerprint changes as well.  Instead of sending back the modification time, the server can send back the ETag (fingerprint):  Etag example : ead145f  File Contents could be an image, HTML, CSS, JavaScript..)  The ETag can be any string which uniquely identifies the file. The next time the browser needs logo.png, it can have a conversation like this
  • 19. HTTP Caching – ETag (Entity tags)  Etag Caching
  • 20. CDN  A content delivery network or content distribution network (CDN) is a system of computers containing copies of data, placed at various points in a network so as to maximize bandwidth for access to the data from clients throughout the network.  A client accesses a copy of the data near to the client, as opposed to all clients accessing the same central server, so as to avoid bottlenecks near that server.  Content types include web objects, downloadable objects (media files, software, documents), applications, real time media streams, and other components of internet delivery (DNS, routes, and database queries).  Not Replicated Servers.
  • 21. Commercial CDN  Akamai Technologies  Amazon CloudFront  AT&T  Bitgravity  CDNetworks  Chinacache  Cotendo  EdgeCast Networks  Highwinds Network Group  Internap  Level 3 Communications  Limelight Networks  Microsoft Windows Azure CDN  Mirror Image Internet  NetDNA
  • 22. Runtime – HTTP Compressions  Runtime HTTP Compressions  Configuring HTTP Compression in IIS  http://technet.microsoft.com/en-us/library/cc771003%28WS.10%29.aspx  Note : It is not enabled by default.  Configuring HTTP GZIP Compression in APACHE  http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip- compression/  Note : Need to install GZIP modules and configure with Apache.
  • 23. Valid W3C compliant page  http://validator.w3.org/  Not just for cross browser rendering & validation.  Helps browsers to quickly read the documents & render it without getting confused. This avoid a delay in page processing at clients browser.
  • 24. How do I test my Application Performance?  Online Test (Online Testing)  WebPageTest.ORG from AOL. • URL : http://www.webpagetest.org  It provides : • Waterfall Load Pattern • HTTP Response Object Load Pattern and time. • Optimization Checklist.  Test on Workstation (Offline Testing)  YSlow plug-in for Firebug in Firefox, from Yahoo Developer Network.  URL : http://developer.yahoo.com/yslow/ • Does not provide Waterfall Load Pattern • Only provides Optimization Checklist.
  • 25. Reference  Yahoo Client/Server Developer reference  http://developer.yahoo.com/performance/rules.html  Google Client/Server Developer reference  http://code.google.com/speed/page-speed/docs/rules_intro.html  W3C standards compliant Web sites  http://www.w3.org/QA/2002/07/WebAgency-Requirements