SlideShare a Scribd company logo
Tuning Web Performance
    in Frontend Perspective

  Lin-Chieh Shangkuan (上官林傑)
         ericsk@gmail.com
AGENDA

 The Impacts of Web Performance
 Development Tools
 Website Optimization Concepts
 References
The Impact of Performance

 Longer response time from web server.
 Too many requests (css/javascript files, images, flashes, ...)
 Complicated DOM structure
 Inefficient JavaScript codes
 ....
The Impact of Performance

 Longer response time from web server.
 Too many requests (css/javascript files, images,
 flashes, ...)
 Complicated DOM structure
 Inefficient JavaScript codes


                                80~90% time spent
                                on the frontend

Recommended for you

Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the IslandsOpening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the Islands

The document discusses various standards that are helping to bridge isolated social networks and enable interoperability across platforms, including OpenID, WebFinger, XRD, PubSubHubbub, Salmon, OAuth, XAuth, OEmbed, and OpenSocial. It provides examples of how these standards work to allow users to log in or comment on different sites without separate accounts, share updates across networks, and embed content like videos universally. While progress is being made, challenges remain around user identity, privacy, access control, and full adoption. The overall goal is a more open and interconnected social web.

pubsubhubbuboembedsalmon
WebPagetest - Good, Bad & Ugly
WebPagetest - Good, Bad & UglyWebPagetest - Good, Bad & Ugly
WebPagetest - Good, Bad & Ugly

Presentation by @aaronpeters at Dutch Web Performance Meetup on August 22 2012. The presentation covers new stuff in WPT UI, the WPT API, scripting and hidden gems. Awesome tool, but also room for improvement.

web performance
Seatwave Web Peformance Optimisation Case Study
Seatwave Web Peformance Optimisation Case StudySeatwave Web Peformance Optimisation Case Study
Seatwave Web Peformance Optimisation Case Study

A web performance optimisation case study presented by Seatwave at the London Web Performance Meetup, Jan 2011. The PDF is in Landscape so you might be better to download it and then shift-ctrl-+ to rotate it clockwise in Adobe Acrobat Reader.

webperfwpoweb performance optimisation
Page-loading Samples
Development Tools

 Firefox
 http://getfirefox.com/
 Firebug
 http://getfirebug.com/
 Page Speed (Firebug plugin)
 http://code.google.com/speed/page-speed/
 Y!Slow
 http://developer.yahoo.com/yslow/
Development Tools (cont)

 Chrome (Chromium/WebKit) Developer Tools
 http://www.chromium.org/devtools
 Install AMAP Latest Web Browsers
 e.g. IE8/9 (preview), Firefox 3.6/nightly, Safari 4/WebKit,
 Chrome/Chromium, Opera 10/10.5
Firebug Console

 Debugging your JavaScript code.
    Use console object in your JavaScript code.
    Interactive in the console tab.

Recommended for you

Keypoints html5
Keypoints html5Keypoints html5
Keypoints html5

20100807 OSC Nagoya での講演資料 # スライドのみで見やすいよう若干整理 P5〜 Agenda P17〜 "HTML5" って何? P56〜 HTML5 の範囲は? P67〜 ブラウザのサポートは? P94〜 IE6 はどうするの? P118〜 使用上の注意 P147〜 便利なツールは? P152〜 One Point Q&A P186〜 追加資料

whatwghtml5webgl
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

The document discusses JavaScript basics and modular JavaScript design. It provides an agenda that covers JavaScript execution, scopes, types, browser objects, blocks, closures, DOM, event handling, and AJAX. It then discusses object-oriented JavaScript, components, containers, layouts, and client-side MVC patterns for modular JavaScript design. Examples of leveraging standards like HTML, CSS, and JavaScript across devices are also provided.

appjavascriptweb
London Web Performance Meetup: Performance for mortal companies
London Web Performance Meetup: Performance for mortal companiesLondon Web Performance Meetup: Performance for mortal companies
London Web Performance Meetup: Performance for mortal companies

You're probably familiar with the well-known performance success stories from companies like Amazon, Google, Microsoft and Shopzilla. But how relevant are these megasites to "mortal companies" that don't make billions of dollars per year or have teams of in-house performance engineers to do their bidding? Strangeloop president Joshua Bixby walks through case studies of Strangeloop customers like AutoAnything.com and Artbeads.com to show how mortal companies have improved performance and achieved measurable success, including: · Increased revenue by 13% · Increased cart size by 6% · Increased conversions by 9% Joshua offers practical tips for successfully evangelizing performance within your organization. He also gives a snapshot of the current performance landscape in North America, as well as a sense of where the industry is headed.

wpoweb content optimizationwebsite speed
Requests Analysis

 Analyzing the requests.
Listen to Suggestions

 Follow the suggestions from PageSpeed (or Y!Slow)
Chromium Devtools
HTTP Overviews

Request:
  GET /foo/bar.js HTTP/1.1
  Host: example.com
  User-Agent: Mozilla/5.0

Response:
  HTTP/1.1 200 OK
  Content-Type: application/x-javascript
  Last-Modified: Mon, 15 Mar 2010 10:00:00 GMT
  Content-Length: 1234

  (function(){ .....

Recommended for you

How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for you

The document discusses Asynchronous JavaScript and XML (Ajax) and how it can be used to retrieve data from a server without reloading the entire web page. It provides an overview of Ajax fundamentals including the XMLHttpRequest object, DOM manipulation, and different data transport options. It also recommends using a JavaScript library to simplify making Ajax requests instead of writing raw XMLHttpRequest code.

Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsers

This document summarizes upcoming improvements and new features in web browsers, including Firefox 3.1, Safari 4, Internet Explorer 8, Opera 10, and Google Chrome. Many of the browsers are focusing on better JavaScript performance through new engines like TraceMonkey and V8. New features include process per tab, postMessage for cross-domain communication, HTML5 drag and drop, and the Canvas element for offloading rendering to the client. Overall the browsers are aiming to improve speed, compatibility, and the user experience through these new features and technologies.

javascriptdombrowsers
Web Page Test - Beyond the Basics
Web Page Test - Beyond the BasicsWeb Page Test - Beyond the Basics
Web Page Test - Beyond the Basics

WebPageTest is a great tool for testing and analysing how quickly web pages load. Many people just use it as a simple testing tool, but it has advanced scripting capabilities for multi-page testing, completing forms etc. It also has an API so performance testing can be integrated into Continuous Integration processes, used for monitoring and analysing how the web is built. These slides explore some of these capabilities in more detail. There are bonus slides after the "Thank You" slide

webpagetestweb performancevelocity
HTTP Reuqest Example
$ telnet ajax.googleapis.com 80
Trying 74.125.153.95...
Connected to googleapis-ajax.l.google.com.
Escape character is '^]'.
GET /ajax/libs/jquery/1.4.2/jquery.min.js HTTP/1.1
Host: ajax.googleapis.com
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; zh-TW; rv:1.9.2)
Gecko/20100115 Firefox/3.6 GTB7.0
Accept-Encoding: gzip,deflate

HTTP/1.1 200 OK
Content-Type: text/javascript; charset=UTF-8
Last-Modified: Mon, 15 Feb 2010 23:30:12 GMT
Date: Mon, 15 Mar 2010 08:39:18 GMT
Expires: Tue, 15 Mar 2011 08:39:18 GMT
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Server: sffe
Content-Encoding: gzip
Cache-Control: public, max-age=31536000
Age: 2497
Content-Length: 24678
X-XSS-Protection: 0

;iw?F???+??m?@ə???v?I։/M???6???????$e???...
Ways to Speed up the Website

 Optimize the backend processing
    e.g., PHP engine, database, ....
 Scaling Transfers
    Co-location, CDN, ...
 Reducing the browser's requests
    CSS sprites, expire headers, http compression...
 Optimizing the contents
    Defer loading, rearrangement, ...
 Efficient JavaScript development
    Improving the programming techs, ...
Scaling Transfers

 Use CDN
    e.g., Akamai, Amazon S3, ...
    Pixnet experience: http://www.slideshare.net/gslin/using-cdn-
    to-improve-performance
 Reduce DNS Lookups
    Keep-Alive
    fewer domains
 Avoid Redirects
 Use Comet
Scaling Transfers

 Sharding Dominant Domains
  browser     HTTP/1.1   HTTP/1.0
  IE6, 7      2          4

  IE8         6          6

  FF2         2          8

  FF3         6          6

  Saf         4          4

  Chrome      6          6

  Op          4          4


        Connections per server

Recommended for you

soft-shake.ch - Introduction to HTML5
soft-shake.ch - Introduction to HTML5soft-shake.ch - Introduction to HTML5
soft-shake.ch - Introduction to HTML5

Sascha Corti With Internet Explorer 9, Microsoft has entered the league of HTML 5 browsers and with its active participation in the W3C working groups, the company proves its engagements towards the new and emerging standards. Developers however are often left wondering where the boundaries are drawn between HTML5 web site, plug-in based rich internet application and smart client or “app”. This session intends to answer this question and uses many examples to show you some of the most important enhancements introduced by HTML5, CSS3, SVG, DOM, WOFF and ECMA script. You will learn now the standards are still evolving and how Microsoft is contributing. http://soft-shake.ch/2011/conference/sessions/microsoft/2011/09/06/introduction-to-html5.html

microsoftsoftshake2011softshake
Echo HTML5
Echo HTML5Echo HTML5
Echo HTML5

Slides I co-presented with John Dyer at the 2010 Echo Conference in Dallas, TX. http://johndyer.name/ http://echoconference.com/

echo conferencehtml5css3
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMix

This document summarizes a presentation about Service Oriented Integration with Apache ServiceMix. The presentation introduces Enterprise Service Buses and their purpose in facilitating integration. It then discusses key aspects of Apache ServiceMix, an open source ESB, including its support for various protocols and engines. The presentation provides examples of how ServiceMix can be used to configure routing and mediation using tools like Apache Camel and content-based routing. It concludes by discussing newer developments in ServiceMix 4 that utilize OSGi and build upon integration patterns.

apacheservicemixservicemix
Reducing Requests
HTTP Compression

 Modern browsers support HTTP compression -- to reduce
 the size of response content
   Gzip the static (html, css, js, ...) files
   Don't compress everything (e.g., jpg, png, pdf, ... they are
   already compressed)
 Check if the Accept-Encoding header has gzip or deflate value.
   Respond Content-Encoding: gzip header.
HTTP Compression

   In Apache httpd server, use mod_gzip (httpd 1.3) or
   mod_deflate (httpd 2.x).

[mod_deflate]
AddOutputFilterByType DEFLATE text/html text/css
application/x-javascript

   Problems:
      Proxy may cache uncompressed content
          Add Vary: Accept-Encoding header
      IE6 bug: Q312496, Q313712
Make Fewer Requests

 CSS Sprites: Combine N icons into 1 bigger image.
    Reduce N requests info 1 request.
    Be careful of the arrangement of the icons
    sample: http://www.google.com.tw/images/nav_logo8.png
    tool: http://tw.spritegen.website-performance.org/
    http://csssprites.com/
 Combine CSS/JavaScript files
    Using Google Closure Compiler
    Apache: http://code.google.com/p/modconcat/
    Lighttpd: http://code.google.com/p/lighttpd-mod-concat/
    YUI Comobo Handler: http://yuiblog.
    com/blog/2008/07/16/combohandler/

Recommended for you

HTML5 Real-Time and Connectivity
HTML5 Real-Time and ConnectivityHTML5 Real-Time and Connectivity
HTML5 Real-Time and Connectivity

These are the slides from my "HTML5 Real-TIme and Connectivity" presentation at the San Francisco HTML5 User Group (http://sfhtml5.org). The presentation covers: Web Origin Cross Document Messaging (PostMessage) CORS XHR Level2 WebSocket Server-Sent Events (EventSource) SPDY

html5 communicationhtml5websockets
Costruire applicazioni multi-tenant e piattaforme SaaS in PHP con Innomatic
Costruire applicazioni multi-tenant e piattaforme SaaS in PHP con InnomaticCostruire applicazioni multi-tenant e piattaforme SaaS in PHP con Innomatic
Costruire applicazioni multi-tenant e piattaforme SaaS in PHP con Innomatic

Innomatic è la piattaforma open source per creare applicazioni multi-tenant e piattaforme SaaS in PHP.

saasmulti-tenantphp
CouchDB Google
CouchDB GoogleCouchDB Google
CouchDB Google

CouchDB is a document-oriented NoSQL database that uses JSON documents with schema-free design. It features a built-in map/reduce function for querying indexes, and uses HTTP for an API and replication. CouchDB is robust, scales well, and is designed for high availability through its append-only writing and multi-version concurrency control.

Make Fewer Requests

 Reduce Cookie size (or split domains)
 Inline images: using base64 encoding
    <img src="data:image/png;base64, xxxxx">
    IE7/6 doesn't support this feature
    Useful in mobile browser
    Not only images: <frame src="data:text/html,%3Chtml%3E%
    3Cbody%20style%3D%22background..."></frame>
Using Expires Headers

 Use Expires header to tell the browser how long to keep
 the resource.
    Browser won't fetch the resource again until the expire time
    Apache mod_expires module can help setting expire time
        <FilesMatch ".(css|js|jpg|png)$">
            ExpiresDefault "access plus 1 year"
        </FilesMatch>
    e.g., Expires: Fri, 25 Mar 2011 08:00:00 GMT
 Cache-Control header
    In stead of using a specified date, Cache-Control header
    shows HOW LONG the client should keep it
    e.g., Cache-Control: max-age=31536000 # cache 1 year
Using Last-Modified Headers

    Use Last-Modified header to tell the browser the last modified
    time of the resource.

[request]                             [request]
GET /foo/bar.css HTTP/1.1             GET /foo/bar.css HTTP/1.1
....                                  ...
                                      If-Modified-Since: Thu, 25 Mar 2010
[response]                            10:00:00 GMT
HTTP/1.1 200 OK                       ...
Content-Type: text/css
Last-Modified: Thu, 25 Mar 2010 10:   [response]
00:00 GMT+8                           HTTP/1.1 304 Not Modified
....                                  ...
                                      (empty response body)
Configuring ETag

 ETag (Entity Tag) header tells browser which to cache
    How ETag works: read Wikipedia
 Problem: Not-the-same tag across different servers
    Apache: inode-size-timestamp
    IIS: timestamp:changenumber

 Solution:
    Set ETag manually
    Remove it.
        (in Apache) FileETag none

Recommended for you

Spring 3 - Der dritte Frühling
Spring 3 - Der dritte FrühlingSpring 3 - Der dritte Frühling
Spring 3 - Der dritte Frühling

»Spring 3« ist da. Vieles ist geblieben, manches verschwunden, manches neu. Spring 3 verspricht eine verbesserte und dynamischere Konfiguration, einen leistungsfähigen und mächtigen REST-Support und viele kleine Verbesserungen. Parallel zu dem Spring 3-Release wurden auch andere Tools und Projekte aktualisiert, auf die wir ebenfalls einen Blick werfen wollen: * Wichtige Änderungen * Java Configuration * Spring Expression Language * Spring MVC und Rest * Embedded Database * SpringSource Toolsuite * Spring Roo * Grails

Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and MavenWebtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven

The most difficult part to test is the WebUI. This part of an application only manually tested. With Selenium you are able to test WebUIs on a simple way. In this article we shows you how to automating the test process.

webtestseleniumgroovy
Bubbles12whole
Bubbles12wholeBubbles12whole
Bubbles12whole

The document describes different types and sizes of bubbles floating, bouncing, dancing, splashing, and popping as well as blowing bubbles and watching them float. Big bubbles splash while little bubbles dance and float with medium and long bubbles in lots of colorful bubbles.

Invalidates the Cached Resources

 If the static resources are cached, how to invalidate them?
    Use signature in filename ( /js/foo.AB32FDC.js )
    Add query string ( /js/foo.js?20100325110000 )
Optimizing Loadings
Minifying JavaScript
 Reduce the size of JavaScript files.
    Reduce the total response sizes.
    HTML, CSS files can be also compressed.
 Closure-compiler
    Web-based http://closure-compiler.appspot.com/
    RESTful API
    http://code.google.com/closure/compiler/docs/api-ref.html
    Standalone executable
 Ofuscation
    Reduce the length of variables names
    Be careful the obfuscation method (e.g., eval cause
    performance degradation)
    Be careful the conflicts.
Optimizing Images

 Using appropriate image format and remove redundant
 chunks in the image files.
    PNG8 (256 colors) is a good choice.
 Optimizing:
    Crushing PNGs
       pngcrush (http://pmt.sf.net/pngcrush/)
    Stripping JPEG metadata
       jpegtran (http://jpegclub.org/)
    Convert GIF to PNG
       ImageMagick
    Optimizing GIF animations
       gifsicle
       (
       (http://www.lcdf.org/gifsicle/)
    Avoid image scaling

Recommended for you

An Introduction to GAEO web framework
An Introduction to GAEO web frameworkAn Introduction to GAEO web framework
An Introduction to GAEO web framework

This document provides an overview of the GAEO web framework for Google App Engine. It discusses what GAEO is, how it works, and how to use it. Key points include that GAEO is a Model-View-Controller based framework inspired by Rails and Zend Framework. It uses URL routing, action controllers, models and templates. The document also outlines GAEO's architecture, code layout, URL routing conventions, action controllers and models. It provides instructions on installing and using GAEO utilities to generate projects.

appenginegoogle
Intro. to JavaScript
Intro. to JavaScriptIntro. to JavaScript
Intro. to JavaScript
Microsoft and jQuery
Microsoft and jQueryMicrosoft and jQuery
Microsoft and jQuery

1) The document discusses Microsoft's close relationship with the jQuery community. It describes how Microsoft products like Visual Studio integrate with jQuery and how Microsoft contributes to official jQuery plugins. 2) It provides an overview of jQuery, including its capabilities and sample code. It also summarizes Microsoft's contributions to jQuery like the jQuery template and datalink plugins. 3) The document concludes by mentioning additional jQuery resources like the JSDefer script loader and encourages following Boris Moore's GitHub repositories for future jQuery developments.

microsoftosdctwjquery
Put Stylesheets on The Top

 Browser delays showing any visible components while it
 and user wait for the stylesheet at the bottom.
 Use <link> to include stylesheets
    @import MUST precede all other rules
    @import may cause blank white screen phenomenon (in IE)
Put JavaScripts at The Bottom

 JavaScript blocks parallel downloads
    Put at top: the other components are delayed- loaded.
 defer attributes:
    Firefox still blocks other downloads
Non-blocking Loading Scripts

 IE8 is the first browser that supports downloading scripts in
 parallel.
 Ways to load JavaScripts
    XHR Eval
    XHR Inject
    Script in iframe
    Inserting script DOM element
    document.write
Non-blocking Loading Scripts
                                                 Existing         Busy           Preserve
     Tech            Parallel      Diff Domain
                                                 Scripts        indicator         Order


    Normal           IE8, SF4          Y            Y       IE, SF4          IE, SF4


   XHR Eval              *             N            N       SF, Ch


 XHR Injection           *             N            Y       SF, Ch


Script in iframe         *             N            N       IE, FF, SF, Ch


  Script DOM             *             Y            Y       FF, SF, Ch       FF, Op


                   IE, SF4, Ch2,
 Script Defer                          Y            Y       *                *
                       FF3.1

                   IE, SF4, Ch2,
document.write                         Y            Y       *                *
                        Op

Recommended for you

08 06 Petley Round Table
08 06 Petley Round Table08 06 Petley Round Table
08 06 Petley Round Table

1. The document discusses the challenges of predicting and managing slow-moving rockslides that can suddenly transition to catastrophic failure. 2. It examines three mechanical states that rockslides can be in - movement along a fully formed shear surface, movement associated with the ongoing formation of a critical shear surface through progressive failure, and creep. 3. The key issues are differentiating between these states, understanding how geometry and the mechanical properties and stress state of the slope materials influence failure, and whether a standard factor of safety approach can be reliably used to forecast behavior.

08 06 Xian Saito Talk 2003v
08 06 Xian Saito Talk 2003v08 06 Xian Saito Talk 2003v
08 06 Xian Saito Talk 2003v

Presentation at the 10th International Symposium on Landslides and Engineered Slopes entitled "Temporal prediction in landslides – understanding the Saito effect"

Internet Explorer 10: 重新想像網站設計
Internet Explorer 10: 重新想像網站設計Internet Explorer 10: 重新想像網站設計
Internet Explorer 10: 重新想像網站設計

Internet Explorer 10重新設計網站介面,利用HTML5和CSS3提升效能和排版。IE10支援觸控操作、手勢事件和釘選網站。開發者可以針對不同解析度和裝置設定不同樣式,並讓網站在Windows 8下快速翻頁和子母畫面切換。IE10也可以將網站打包成App發佈。

htmlhtml5microsoft
iframes

 iframes are heavy and block onload event.
 Use script DOM injection to insert ADs instead of iframes.
Efficiency Practices
Make JavaScript/CSS External

 Reusing components
 Cache the files
 Unobstrusive JavaScripts
Simplifying CSS Selectors

 CSS selector policy: Rightmost-First
 Tips:
    Avoid * selector
    Don't qualify ID/CSS selectors
    Specific rules
    Avoid descendant selectors
    Avoid Tag > Child selectors
    Rely on inheritance

Recommended for you

High Performance Web Pages - 20 new best practices
High Performance Web Pages - 20 new best practicesHigh Performance Web Pages - 20 new best practices
High Performance Web Pages - 20 new best practices

The document discusses best practices for improving web page performance. It begins by noting how slow pages negatively impact user experience and business metrics. It then outlines 14 best practices such as minimizing HTTP requests, using a content delivery network, gzipping components, optimizing images, and avoiding redirects. Additional best practices are also provided such as preloading components, minimizing DOM access, and keeping components under 25kb. Tools for measuring performance are also mentioned.

Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations

The document discusses optimization of the presentation tier of web applications. It notes that the presentation tier is often overlooked despite being responsible for over 30% of client/server performance. Some key optimizations discussed include reducing HTTP requests, optimizing response objects by reducing size and load pattern, JavaScript minification and placement, image sprites, caching, and ensuring valid HTML markup.

htmlcssjavascript
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NETSilicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET

This document provides an overview and introduction to using ExtJS with ASP.NET for building high performance AJAX applications. It covers setting up Visual Studio for JavaScript development, debugging techniques, an introduction to ExtJS, examples of ExtJS components like grids and form panels, handling errors, and tips for optimizing AJAX performance.

netjavascriptajax
Efficient JavaScript Tips

 Using className instead of modifying style attributes of a DOM
 element.
 [bad
 ]

 var foo = document.getElementById('foo');
 foo.style.color = '#f00';
 foo.style.fontWeight = 'bold';

 [good]
 .highlight {
    color: #f00;
    font-weight: bold;
 }

 foo.className = 'highlight';
Efficient JavaScript Tips (con'd)

 Appending a newly-created DOM element after modifying its
 attributes. (avoid reflows)
 [bad]
 var foo = document.createElement('div');
 document.body.appendChild(foo);
 foo.innerHTML = 'Hello, world';
 foo.className = 'hello';

 [good]
 var foo = document.createElement('div');
 foo.innerHTML = 'Hello, world';
 foo.className = 'hello';
 document.body.appendChild(foo);
Efficient JavaScript Tips

 Using document fragment to create new contents.
 [bad]
 document.body.appendChild(createDivElement());
 document.body.appendChild(createDivElement());
 ...

 [good]
 var frag = document.createDocumentFragment();
 frag.appendChild(createDivElement());
 frag.appendChild(createDivElement());
 ....
 document.body.appendChild(frag);
Efficient JavaScript Tips

 Using array join instead of directly concatenate strings.
 [bad
 ]
 ]
 var a = 'Hel';
 a += 'lo';
 a += ', wor';
 a += 'ld!';

 [good]
 var buf = ['Hel'];
 buf.push('lo');
 buf.push(', wor');
 buf.push('ld!');
 a = buf.join('');

Recommended for you

Front End Website Optimization
Front End Website OptimizationFront End Website Optimization
Front End Website Optimization

Yahoo has developed the de facto standard for building fast front-ends for websites. The bad news: you have to follow 34 rules to get there. The good news: I'll take a subset of those rules, explain them, and show how you can implement those rules in an automated fashion to minimize impact on developers and designers for your high-traffic website.

yslowphpoptimization
Life on the Edge with ESI
Life on the Edge with ESILife on the Edge with ESI
Life on the Edge with ESI

This document discusses Edge Side Includes (ESI) and its use at Yahoo. ESI allows content to be assembled at the edge from different sources, improving performance. Yahoo uses ESI to assemble pages, support legacy modules, and handle combinations of assets. ESI enables availability through caching and fallbacks. The future may include deeper HTTP integration and smarter assembly of includes.

esicdnedge computing
Front-end optimisation & jQuery Internals
Front-end optimisation & jQuery InternalsFront-end optimisation & jQuery Internals
Front-end optimisation & jQuery Internals

This document discusses optimizing jQuery and front-end performance. It covers minimizing HTTP requests, file size, and blocking behavior to improve dependency loading. It discusses optimizing initial page rendering through proper asset ordering, lazy loading, and reducing flash of unstyled content. It also discusses minimizing reflows and repaints as well as JavaScript optimizations to improve post-load responsiveness. The document provides an overview of jQuery internals and techniques for optimizing jQuery code.

jquery
Efficient JavaScript Tips

   Faster trim method: (use simple regular expression)
[bad]
str.replace(/^s+|s+$/g, '');

[better]
str.replace(/^s+/, '').replace(/^s+$/, '');

[much better]
str = str.replace(/^s+/, '');
for (i = str.length - 1; i >=0; i--) {
    if (/S/.test(str.charAt(i))) {
        str = str.substring(0, i + 1);
        break;
    }
}
Efficient JavaScript Tips

 Use popular JavaScript frameworks. (e.g. jQuery)
Misc.
Responsive Web Applications

 Prefetching resources
 AJAX
 Avoid long-running scripts

Recommended for you

Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind

This document discusses profiling PHP applications to improve performance. It recommends profiling during development to identify inefficiencies. The document introduces Xdebug for profiling PHP code and Webgrind, a PHP frontend for visualizing Xdebug profiles. It provides an example of profiling a sample PHP application, identifying issues, making code changes, and verifying performance improvements through re-profiling.

phpwebgrindxdebug
Optimising Web Application Frontend
Optimising Web Application FrontendOptimising Web Application Frontend
Optimising Web Application Frontend

This document discusses various techniques for optimizing the frontend performance of web applications. It provides 5 rules: 1) Only optimize when it makes a meaningful difference. 2) Download resources in parallel to reduce page load time. 3) Eliminate unnecessary requests through techniques like merging, inlining, sprites and caching. 4) Defer parsing of JavaScripts when possible to improve perceived page load speeds. 5) Consider factors like server location and content delivery networks to improve global performance.

High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications

Day 6 of 7-days "JavaScript and Rich User Interfaces" training for my colleagues. It covers ways how to speed up your application.

yahooperformancejs
HTML5

 http://whatwg.org/html5
 Short tags:
    <!DOCTYPE html>
    <meta charset="UTF-8">
    <script src="xxx.js">, <style>...</style>
    <script async ...>
 Application Cache (offline data)
    https://developer.mozilla.org/En/Offline_resources_in_Firefox
    http://www.whatwg.org/specs/web-apps/current-
    work/multipage/offline.html
    http://googlecode.blogspot.com/2009/04/gmail-for-mobile-
    html5-series-using.html
 WebStorage/WebDatabase API
Mobile Web

 Mobile device has lower hardware-profile so that the web
 performance is more important!
 iPhone Safari/Android browser/Opera Mini likes HTML5 (w/
 a little CSS3)
References
Books

 High Performance Web Sites, O'Reilly
 Even Faster Web Sites

Recommended for you

Frontend performance
Frontend performanceFrontend performance
Frontend performance

The document provides best practices for optimizing frontend performance by reducing page load time. It discusses ways to reduce the number of HTTP requests, DNS lookups, redirects and duplicate scripts. It also recommends techniques like minifying assets, leveraging caching, prioritizing critical components, optimizing images and using content delivery networks.

performancefrontend
Sandboxing JS and HTML. A lession Learned
Sandboxing JS and HTML. A lession LearnedSandboxing JS and HTML. A lession Learned
Sandboxing JS and HTML. A lession Learned

== Abstract == Presented at Analysis of Security APIs Satellite workshop of IEEE CSF July 13th 2015, Verona, Italy http://www.dsi.unive.it/~focardi/ASA8/#program Browsers HTML sandbox is, by default, only protected by the "Same Origin Policy". Although this simple constraint gave companies a very flexible environment to play with, and was probably one of the key features that led the Web to success as we see it now, it is quite unsatisfactory from a security perspective. In fact, this solution does not face the problem of letting third party code access the whole data in the DOM when explicitly loaded and executed by the browser. This behaviour opens the door to malicious third party code attacks that can be achieved using either Cross Site Scripting (OWASP Top Ten Security risk #1 for many years) or second order attacks, such as malvertising software. In the past, several attempts to sandbox untrusted code have been made. In this talk we will focus on successes and failures of the most interesting open source sandboxing browser techniques.

javascriptsandboxsecurity
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を考える

This document provides an overview of HTML5 technologies including HTML5 markup, microdata/RDFa, WebFonts, Canvas, MediaQueries, performance optimizations like SPDY and HTTP 2.0. It discusses specifications from the W3C and implementations by companies. Tools for testing responsive design, fonts and browser compatibility are also mentioned. The document is written in Japanese and references the author's blog for code samples.

html5html5j
Websites

 Let's Make the Web Faster (Google)
 http://code.google.com/speed
 Exceptional Performance (Yahoo!)
 http://developer.yahoo.com/performance/
 High Performance Web Sites Blog
 http://www.stevesouders.com/blog/

More Related Content

What's hot

Building an HTML5 Video Player
Building an HTML5 Video PlayerBuilding an HTML5 Video Player
Building an HTML5 Video Player
Jim Jeffers
 
S314011 - Developing Composite Applications for the Cloud with Apache Tuscany
S314011 - Developing Composite Applications for the Cloud with Apache TuscanyS314011 - Developing Composite Applications for the Cloud with Apache Tuscany
S314011 - Developing Composite Applications for the Cloud with Apache Tuscany
Luciano Resende
 
Performance automation 101 @LDNWebPerf MickMcGuinness
Performance automation 101 @LDNWebPerf MickMcGuinnessPerformance automation 101 @LDNWebPerf MickMcGuinness
Performance automation 101 @LDNWebPerf MickMcGuinness
Stephen Thair
 
Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the IslandsOpening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the Islands
Bastian Hofmann
 
WebPagetest - Good, Bad & Ugly
WebPagetest - Good, Bad & UglyWebPagetest - Good, Bad & Ugly
WebPagetest - Good, Bad & Ugly
Aaron Peters
 
Seatwave Web Peformance Optimisation Case Study
Seatwave Web Peformance Optimisation Case StudySeatwave Web Peformance Optimisation Case Study
Seatwave Web Peformance Optimisation Case Study
Stephen Thair
 
Keypoints html5
Keypoints html5Keypoints html5
Keypoints html5
dynamis
 
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
AppUniverz Org
 
London Web Performance Meetup: Performance for mortal companies
London Web Performance Meetup: Performance for mortal companiesLondon Web Performance Meetup: Performance for mortal companies
London Web Performance Meetup: Performance for mortal companies
Strangeloop
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for you
Simon Willison
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsers
jeresig
 
Web Page Test - Beyond the Basics
Web Page Test - Beyond the BasicsWeb Page Test - Beyond the Basics
Web Page Test - Beyond the Basics
Andy Davies
 
soft-shake.ch - Introduction to HTML5
soft-shake.ch - Introduction to HTML5soft-shake.ch - Introduction to HTML5
soft-shake.ch - Introduction to HTML5
soft-shake.ch
 
Echo HTML5
Echo HTML5Echo HTML5
Echo HTML5
Nathan Smith
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMix
Bruce Snyder
 
HTML5 Real-Time and Connectivity
HTML5 Real-Time and ConnectivityHTML5 Real-Time and Connectivity
HTML5 Real-Time and Connectivity
Peter Lubbers
 
Costruire applicazioni multi-tenant e piattaforme SaaS in PHP con Innomatic
Costruire applicazioni multi-tenant e piattaforme SaaS in PHP con InnomaticCostruire applicazioni multi-tenant e piattaforme SaaS in PHP con Innomatic
Costruire applicazioni multi-tenant e piattaforme SaaS in PHP con Innomatic
Innoteam Srl
 
CouchDB Google
CouchDB GoogleCouchDB Google
CouchDB Google
Steve Souders
 
Spring 3 - Der dritte Frühling
Spring 3 - Der dritte FrühlingSpring 3 - Der dritte Frühling
Spring 3 - Der dritte Frühling
Thorsten Kamann
 
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and MavenWebtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Thorsten Kamann
 

What's hot (20)

Building an HTML5 Video Player
Building an HTML5 Video PlayerBuilding an HTML5 Video Player
Building an HTML5 Video Player
 
S314011 - Developing Composite Applications for the Cloud with Apache Tuscany
S314011 - Developing Composite Applications for the Cloud with Apache TuscanyS314011 - Developing Composite Applications for the Cloud with Apache Tuscany
S314011 - Developing Composite Applications for the Cloud with Apache Tuscany
 
Performance automation 101 @LDNWebPerf MickMcGuinness
Performance automation 101 @LDNWebPerf MickMcGuinnessPerformance automation 101 @LDNWebPerf MickMcGuinness
Performance automation 101 @LDNWebPerf MickMcGuinness
 
Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the IslandsOpening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the Islands
 
WebPagetest - Good, Bad & Ugly
WebPagetest - Good, Bad & UglyWebPagetest - Good, Bad & Ugly
WebPagetest - Good, Bad & Ugly
 
Seatwave Web Peformance Optimisation Case Study
Seatwave Web Peformance Optimisation Case StudySeatwave Web Peformance Optimisation Case Study
Seatwave Web Peformance Optimisation Case Study
 
Keypoints html5
Keypoints html5Keypoints html5
Keypoints 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
 
London Web Performance Meetup: Performance for mortal companies
London Web Performance Meetup: Performance for mortal companiesLondon Web Performance Meetup: Performance for mortal companies
London Web Performance Meetup: Performance for mortal companies
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for you
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsers
 
Web Page Test - Beyond the Basics
Web Page Test - Beyond the BasicsWeb Page Test - Beyond the Basics
Web Page Test - Beyond the Basics
 
soft-shake.ch - Introduction to HTML5
soft-shake.ch - Introduction to HTML5soft-shake.ch - Introduction to HTML5
soft-shake.ch - Introduction to HTML5
 
Echo HTML5
Echo HTML5Echo HTML5
Echo HTML5
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMix
 
HTML5 Real-Time and Connectivity
HTML5 Real-Time and ConnectivityHTML5 Real-Time and Connectivity
HTML5 Real-Time and Connectivity
 
Costruire applicazioni multi-tenant e piattaforme SaaS in PHP con Innomatic
Costruire applicazioni multi-tenant e piattaforme SaaS in PHP con InnomaticCostruire applicazioni multi-tenant e piattaforme SaaS in PHP con Innomatic
Costruire applicazioni multi-tenant e piattaforme SaaS in PHP con Innomatic
 
CouchDB Google
CouchDB GoogleCouchDB Google
CouchDB Google
 
Spring 3 - Der dritte Frühling
Spring 3 - Der dritte FrühlingSpring 3 - Der dritte Frühling
Spring 3 - Der dritte Frühling
 
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and MavenWebtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
 

Viewers also liked

Bubbles12whole
Bubbles12wholeBubbles12whole
Bubbles12whole
Room6stjos
 
An Introduction to GAEO web framework
An Introduction to GAEO web frameworkAn Introduction to GAEO web framework
An Introduction to GAEO web framework
Eric ShangKuan
 
Microsoft and jQuery
Microsoft and jQueryMicrosoft and jQuery
Microsoft and jQuery
Eric ShangKuan
 
08 06 Petley Round Table
08 06 Petley Round Table08 06 Petley Round Table
08 06 Petley Round Table
Dr_Dave
 
08 06 Xian Saito Talk 2003v
08 06 Xian Saito Talk 2003v08 06 Xian Saito Talk 2003v
08 06 Xian Saito Talk 2003v
Dr_Dave
 
Internet Explorer 10: 重新想像網站設計
Internet Explorer 10: 重新想像網站設計Internet Explorer 10: 重新想像網站設計
Internet Explorer 10: 重新想像網站設計
Eric ShangKuan
 

Viewers also liked (7)

Bubbles12whole
Bubbles12wholeBubbles12whole
Bubbles12whole
 
An Introduction to GAEO web framework
An Introduction to GAEO web frameworkAn Introduction to GAEO web framework
An Introduction to GAEO web framework
 
Intro. to JavaScript
Intro. to JavaScriptIntro. to JavaScript
Intro. to JavaScript
 
Microsoft and jQuery
Microsoft and jQueryMicrosoft and jQuery
Microsoft and jQuery
 
08 06 Petley Round Table
08 06 Petley Round Table08 06 Petley Round Table
08 06 Petley Round Table
 
08 06 Xian Saito Talk 2003v
08 06 Xian Saito Talk 2003v08 06 Xian Saito Talk 2003v
08 06 Xian Saito Talk 2003v
 
Internet Explorer 10: 重新想像網站設計
Internet Explorer 10: 重新想像網站設計Internet Explorer 10: 重新想像網站設計
Internet Explorer 10: 重新想像網站設計
 

Similar to Tuning Web Performance

High Performance Web Pages - 20 new best practices
High Performance Web Pages - 20 new best practicesHigh Performance Web Pages - 20 new best practices
High Performance Web Pages - 20 new best practices
Stoyan Stefanov
 
Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
Anup Hariharan Nair
 
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NETSilicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Mats Bryntse
 
Front End Website Optimization
Front End Website OptimizationFront End Website Optimization
Front End Website Optimization
Gerard Sychay
 
Life on the Edge with ESI
Life on the Edge with ESILife on the Edge with ESI
Life on the Edge with ESI
Kit Chan
 
Front-end optimisation & jQuery Internals
Front-end optimisation & jQuery InternalsFront-end optimisation & jQuery Internals
Front-end optimisation & jQuery Internals
Artur Cistov
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
Sam Keen
 
Optimising Web Application Frontend
Optimising Web Application FrontendOptimising Web Application Frontend
Optimising Web Application Frontend
tkramar
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
Siarhei Barysiuk
 
Frontend performance
Frontend performanceFrontend performance
Frontend performance
sacred 8
 
Sandboxing JS and HTML. A lession Learned
Sandboxing JS and HTML. A lession LearnedSandboxing JS and HTML. A lession Learned
Sandboxing JS and HTML. A lession Learned
Minded Security
 
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を考える
Sadaaki HIRAI
 
Sanjeev ghai 12
Sanjeev ghai 12Sanjeev ghai 12
Sanjeev ghai 12
Praveen kumar
 
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Sadaaki HIRAI
 
前端概述
前端概述前端概述
前端概述
Ethan Zhang
 
Front-end performances
Front-end performancesFront-end performances
Front-end performances
Smile I.T is open
 
jQuery Tips Tricks Trivia
jQuery Tips Tricks TriviajQuery Tips Tricks Trivia
jQuery Tips Tricks Trivia
Cognizant
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
zonathen
 
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterPractical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Doris Chen
 
High-Speed HTML5
High-Speed HTML5High-Speed HTML5
High-Speed HTML5
Peter Lubbers
 

Similar to Tuning Web Performance (20)

High Performance Web Pages - 20 new best practices
High Performance Web Pages - 20 new best practicesHigh Performance Web Pages - 20 new best practices
High Performance Web Pages - 20 new best practices
 
Presentation Tier optimizations
Presentation Tier optimizationsPresentation Tier optimizations
Presentation Tier optimizations
 
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NETSilicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
 
Front End Website Optimization
Front End Website OptimizationFront End Website Optimization
Front End Website Optimization
 
Life on the Edge with ESI
Life on the Edge with ESILife on the Edge with ESI
Life on the Edge with ESI
 
Front-end optimisation & jQuery Internals
Front-end optimisation & jQuery InternalsFront-end optimisation & jQuery Internals
Front-end optimisation & jQuery Internals
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
Optimising Web Application Frontend
Optimising Web Application FrontendOptimising Web Application Frontend
Optimising Web Application Frontend
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
 
Frontend performance
Frontend performanceFrontend performance
Frontend performance
 
Sandboxing JS and HTML. A lession Learned
Sandboxing JS and HTML. A lession LearnedSandboxing JS and HTML. A lession Learned
Sandboxing JS and HTML. A lession Learned
 
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を考える
 
Sanjeev ghai 12
Sanjeev ghai 12Sanjeev ghai 12
Sanjeev ghai 12
 
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
 
前端概述
前端概述前端概述
前端概述
 
Front-end performances
Front-end performancesFront-end performances
Front-end performances
 
jQuery Tips Tricks Trivia
jQuery Tips Tricks TriviajQuery Tips Tricks Trivia
jQuery Tips Tricks Trivia
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
 
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterPractical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
 
High-Speed HTML5
High-Speed HTML5High-Speed HTML5
High-Speed HTML5
 

More from Eric ShangKuan

運用 Azure Custom Vision 輕鬆開發智慧視覺應用程式
運用 Azure Custom Vision 輕鬆開發智慧視覺應用程式運用 Azure Custom Vision 輕鬆開發智慧視覺應用程式
運用 Azure Custom Vision 輕鬆開發智慧視覺應用程式
Eric ShangKuan
 
Introducing .NET Core Open Source
Introducing .NET Core Open SourceIntroducing .NET Core Open Source
Introducing .NET Core Open Source
Eric ShangKuan
 
In
InIn
Azure machine learning overview
Azure machine learning overviewAzure machine learning overview
Azure machine learning overview
Eric ShangKuan
 
透過 Windows Azure Mobile Services 開發各平台 Apps
透過 Windows Azure Mobile Services 開發各平台 Apps透過 Windows Azure Mobile Services 開發各平台 Apps
透過 Windows Azure Mobile Services 開發各平台 Apps
Eric ShangKuan
 
Metro Style Apps from C++ Developers' View
Metro Style Apps from C++ Developers' ViewMetro Style Apps from C++ Developers' View
Metro Style Apps from C++ Developers' View
Eric ShangKuan
 
Building Python Applications on Windows Azure
Building Python Applications on Windows AzureBuilding Python Applications on Windows Azure
Building Python Applications on Windows Azure
Eric ShangKuan
 
Intro To Google Maps
Intro To Google MapsIntro To Google Maps
Intro To Google Maps
Eric ShangKuan
 
Practical Google App Engine Applications In Py
Practical Google App Engine Applications In PyPractical Google App Engine Applications In Py
Practical Google App Engine Applications In Py
Eric ShangKuan
 
jQuery Tutorial
jQuery TutorialjQuery Tutorial
jQuery Tutorial
Eric ShangKuan
 
The Google App Engine Oil Framework
The Google App Engine Oil FrameworkThe Google App Engine Oil Framework
The Google App Engine Oil Framework
Eric ShangKuan
 

More from Eric ShangKuan (12)

運用 Azure Custom Vision 輕鬆開發智慧視覺應用程式
運用 Azure Custom Vision 輕鬆開發智慧視覺應用程式運用 Azure Custom Vision 輕鬆開發智慧視覺應用程式
運用 Azure Custom Vision 輕鬆開發智慧視覺應用程式
 
Introducing .NET Core Open Source
Introducing .NET Core Open SourceIntroducing .NET Core Open Source
Introducing .NET Core Open Source
 
In
InIn
In
 
Azure machine learning overview
Azure machine learning overviewAzure machine learning overview
Azure machine learning overview
 
透過 Windows Azure Mobile Services 開發各平台 Apps
透過 Windows Azure Mobile Services 開發各平台 Apps透過 Windows Azure Mobile Services 開發各平台 Apps
透過 Windows Azure Mobile Services 開發各平台 Apps
 
Metro Style Apps from C++ Developers' View
Metro Style Apps from C++ Developers' ViewMetro Style Apps from C++ Developers' View
Metro Style Apps from C++ Developers' View
 
Building Python Applications on Windows Azure
Building Python Applications on Windows AzureBuilding Python Applications on Windows Azure
Building Python Applications on Windows Azure
 
Intro To Google Maps
Intro To Google MapsIntro To Google Maps
Intro To Google Maps
 
Practical Google App Engine Applications In Py
Practical Google App Engine Applications In PyPractical Google App Engine Applications In Py
Practical Google App Engine Applications In Py
 
Intro. to CSS
Intro. to CSSIntro. to CSS
Intro. to CSS
 
jQuery Tutorial
jQuery TutorialjQuery Tutorial
jQuery Tutorial
 
The Google App Engine Oil Framework
The Google App Engine Oil FrameworkThe Google App Engine Oil Framework
The Google App Engine Oil Framework
 

Recently uploaded

The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdfThe Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
JackieSparrow3
 
Views in Odoo - Advanced Views - Pivot View in Odoo 17
Views in Odoo - Advanced Views - Pivot View in Odoo 17Views in Odoo - Advanced Views - Pivot View in Odoo 17
Views in Odoo - Advanced Views - Pivot View in Odoo 17
Celine George
 
DANH SÁCH THÍ SINH XÉT TUYỂN SỚM ĐỦ ĐIỀU KIỆN TRÚNG TUYỂN ĐẠI HỌC CHÍNH QUY N...
DANH SÁCH THÍ SINH XÉT TUYỂN SỚM ĐỦ ĐIỀU KIỆN TRÚNG TUYỂN ĐẠI HỌC CHÍNH QUY N...DANH SÁCH THÍ SINH XÉT TUYỂN SỚM ĐỦ ĐIỀU KIỆN TRÚNG TUYỂN ĐẠI HỌC CHÍNH QUY N...
DANH SÁCH THÍ SINH XÉT TUYỂN SỚM ĐỦ ĐIỀU KIỆN TRÚNG TUYỂN ĐẠI HỌC CHÍNH QUY N...
thanhluan21
 
(T.L.E.) Agriculture: Essentials of Gardening
(T.L.E.) Agriculture: Essentials of Gardening(T.L.E.) Agriculture: Essentials of Gardening
(T.L.E.) Agriculture: Essentials of Gardening
MJDuyan
 
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISINGSYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
Dr Vijay Vishwakarma
 
Howe Writing Center - Orientation Summer 2024
Howe Writing Center - Orientation Summer 2024Howe Writing Center - Orientation Summer 2024
Howe Writing Center - Orientation Summer 2024
Elizabeth Walsh
 
How to Add Colour Kanban Records in Odoo 17 Notebook
How to Add Colour Kanban Records in Odoo 17 NotebookHow to Add Colour Kanban Records in Odoo 17 Notebook
How to Add Colour Kanban Records in Odoo 17 Notebook
Celine George
 
Webinar Innovative assessments for SOcial Emotional Skills
Webinar Innovative assessments for SOcial Emotional SkillsWebinar Innovative assessments for SOcial Emotional Skills
Webinar Innovative assessments for SOcial Emotional Skills
EduSkills OECD
 
How to Configure Time Off Types in Odoo 17
How to Configure Time Off Types in Odoo 17How to Configure Time Off Types in Odoo 17
How to Configure Time Off Types in Odoo 17
Celine George
 
No, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalismNo, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalism
Paul Bradshaw
 
Configuring Single Sign-On (SSO) via Identity Management | MuleSoft Mysore Me...
Configuring Single Sign-On (SSO) via Identity Management | MuleSoft Mysore Me...Configuring Single Sign-On (SSO) via Identity Management | MuleSoft Mysore Me...
Configuring Single Sign-On (SSO) via Identity Management | MuleSoft Mysore Me...
MysoreMuleSoftMeetup
 
NAEYC Code of Ethical Conduct Resource Book
NAEYC Code of Ethical Conduct Resource BookNAEYC Code of Ethical Conduct Resource Book
NAEYC Code of Ethical Conduct Resource Book
lakitawilson
 
National Learning Camp( Reading Intervention for grade1)
National Learning Camp( Reading Intervention for grade1)National Learning Camp( Reading Intervention for grade1)
National Learning Camp( Reading Intervention for grade1)
SaadaGrijaldo1
 
Is Email Marketing Really Effective In 2024?
Is Email Marketing Really Effective In 2024?Is Email Marketing Really Effective In 2024?
Is Email Marketing Really Effective In 2024?
Rakesh Jalan
 
How to Show Sample Data in Tree and Kanban View in Odoo 17
How to Show Sample Data in Tree and Kanban View in Odoo 17How to Show Sample Data in Tree and Kanban View in Odoo 17
How to Show Sample Data in Tree and Kanban View in Odoo 17
Celine George
 
Ardra Nakshatra (आर्द्रा): Understanding its Effects and Remedies
Ardra Nakshatra (आर्द्रा): Understanding its Effects and RemediesArdra Nakshatra (आर्द्रा): Understanding its Effects and Remedies
Ardra Nakshatra (आर्द्रा): Understanding its Effects and Remedies
Astro Pathshala
 
AI_in_HR_Presentation Part 1 2024 0703.pdf
AI_in_HR_Presentation Part 1 2024 0703.pdfAI_in_HR_Presentation Part 1 2024 0703.pdf
AI_in_HR_Presentation Part 1 2024 0703.pdf
SrimanigandanMadurai
 
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
marianell3076
 
The basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxThe basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptx
heathfieldcps1
 
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
siemaillard
 

Recently uploaded (20)

The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdfThe Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
 
Views in Odoo - Advanced Views - Pivot View in Odoo 17
Views in Odoo - Advanced Views - Pivot View in Odoo 17Views in Odoo - Advanced Views - Pivot View in Odoo 17
Views in Odoo - Advanced Views - Pivot View in Odoo 17
 
DANH SÁCH THÍ SINH XÉT TUYỂN SỚM ĐỦ ĐIỀU KIỆN TRÚNG TUYỂN ĐẠI HỌC CHÍNH QUY N...
DANH SÁCH THÍ SINH XÉT TUYỂN SỚM ĐỦ ĐIỀU KIỆN TRÚNG TUYỂN ĐẠI HỌC CHÍNH QUY N...DANH SÁCH THÍ SINH XÉT TUYỂN SỚM ĐỦ ĐIỀU KIỆN TRÚNG TUYỂN ĐẠI HỌC CHÍNH QUY N...
DANH SÁCH THÍ SINH XÉT TUYỂN SỚM ĐỦ ĐIỀU KIỆN TRÚNG TUYỂN ĐẠI HỌC CHÍNH QUY N...
 
(T.L.E.) Agriculture: Essentials of Gardening
(T.L.E.) Agriculture: Essentials of Gardening(T.L.E.) Agriculture: Essentials of Gardening
(T.L.E.) Agriculture: Essentials of Gardening
 
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISINGSYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
SYBCOM SEM III UNIT 1 INTRODUCTION TO ADVERTISING
 
Howe Writing Center - Orientation Summer 2024
Howe Writing Center - Orientation Summer 2024Howe Writing Center - Orientation Summer 2024
Howe Writing Center - Orientation Summer 2024
 
How to Add Colour Kanban Records in Odoo 17 Notebook
How to Add Colour Kanban Records in Odoo 17 NotebookHow to Add Colour Kanban Records in Odoo 17 Notebook
How to Add Colour Kanban Records in Odoo 17 Notebook
 
Webinar Innovative assessments for SOcial Emotional Skills
Webinar Innovative assessments for SOcial Emotional SkillsWebinar Innovative assessments for SOcial Emotional Skills
Webinar Innovative assessments for SOcial Emotional Skills
 
How to Configure Time Off Types in Odoo 17
How to Configure Time Off Types in Odoo 17How to Configure Time Off Types in Odoo 17
How to Configure Time Off Types in Odoo 17
 
No, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalismNo, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalism
 
Configuring Single Sign-On (SSO) via Identity Management | MuleSoft Mysore Me...
Configuring Single Sign-On (SSO) via Identity Management | MuleSoft Mysore Me...Configuring Single Sign-On (SSO) via Identity Management | MuleSoft Mysore Me...
Configuring Single Sign-On (SSO) via Identity Management | MuleSoft Mysore Me...
 
NAEYC Code of Ethical Conduct Resource Book
NAEYC Code of Ethical Conduct Resource BookNAEYC Code of Ethical Conduct Resource Book
NAEYC Code of Ethical Conduct Resource Book
 
National Learning Camp( Reading Intervention for grade1)
National Learning Camp( Reading Intervention for grade1)National Learning Camp( Reading Intervention for grade1)
National Learning Camp( Reading Intervention for grade1)
 
Is Email Marketing Really Effective In 2024?
Is Email Marketing Really Effective In 2024?Is Email Marketing Really Effective In 2024?
Is Email Marketing Really Effective In 2024?
 
How to Show Sample Data in Tree and Kanban View in Odoo 17
How to Show Sample Data in Tree and Kanban View in Odoo 17How to Show Sample Data in Tree and Kanban View in Odoo 17
How to Show Sample Data in Tree and Kanban View in Odoo 17
 
Ardra Nakshatra (आर्द्रा): Understanding its Effects and Remedies
Ardra Nakshatra (आर्द्रा): Understanding its Effects and RemediesArdra Nakshatra (आर्द्रा): Understanding its Effects and Remedies
Ardra Nakshatra (आर्द्रा): Understanding its Effects and Remedies
 
AI_in_HR_Presentation Part 1 2024 0703.pdf
AI_in_HR_Presentation Part 1 2024 0703.pdfAI_in_HR_Presentation Part 1 2024 0703.pdf
AI_in_HR_Presentation Part 1 2024 0703.pdf
 
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
The basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxThe basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptx
 
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
 

Tuning Web Performance

  • 1. Tuning Web Performance in Frontend Perspective Lin-Chieh Shangkuan (上官林傑) ericsk@gmail.com
  • 2. AGENDA The Impacts of Web Performance Development Tools Website Optimization Concepts References
  • 3. The Impact of Performance Longer response time from web server. Too many requests (css/javascript files, images, flashes, ...) Complicated DOM structure Inefficient JavaScript codes ....
  • 4. The Impact of Performance Longer response time from web server. Too many requests (css/javascript files, images, flashes, ...) Complicated DOM structure Inefficient JavaScript codes 80~90% time spent on the frontend
  • 6. Development Tools Firefox http://getfirefox.com/ Firebug http://getfirebug.com/ Page Speed (Firebug plugin) http://code.google.com/speed/page-speed/ Y!Slow http://developer.yahoo.com/yslow/
  • 7. Development Tools (cont) Chrome (Chromium/WebKit) Developer Tools http://www.chromium.org/devtools Install AMAP Latest Web Browsers e.g. IE8/9 (preview), Firefox 3.6/nightly, Safari 4/WebKit, Chrome/Chromium, Opera 10/10.5
  • 8. Firebug Console Debugging your JavaScript code. Use console object in your JavaScript code. Interactive in the console tab.
  • 10. Listen to Suggestions Follow the suggestions from PageSpeed (or Y!Slow)
  • 12. HTTP Overviews Request: GET /foo/bar.js HTTP/1.1 Host: example.com User-Agent: Mozilla/5.0 Response: HTTP/1.1 200 OK Content-Type: application/x-javascript Last-Modified: Mon, 15 Mar 2010 10:00:00 GMT Content-Length: 1234 (function(){ .....
  • 13. HTTP Reuqest Example $ telnet ajax.googleapis.com 80 Trying 74.125.153.95... Connected to googleapis-ajax.l.google.com. Escape character is '^]'. GET /ajax/libs/jquery/1.4.2/jquery.min.js HTTP/1.1 Host: ajax.googleapis.com User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; zh-TW; rv:1.9.2) Gecko/20100115 Firefox/3.6 GTB7.0 Accept-Encoding: gzip,deflate HTTP/1.1 200 OK Content-Type: text/javascript; charset=UTF-8 Last-Modified: Mon, 15 Feb 2010 23:30:12 GMT Date: Mon, 15 Mar 2010 08:39:18 GMT Expires: Tue, 15 Mar 2011 08:39:18 GMT Vary: Accept-Encoding X-Content-Type-Options: nosniff Server: sffe Content-Encoding: gzip Cache-Control: public, max-age=31536000 Age: 2497 Content-Length: 24678 X-XSS-Protection: 0 ;iw?F???+??m?@ə???v?I։/M???6???????$e???...
  • 14. Ways to Speed up the Website Optimize the backend processing e.g., PHP engine, database, .... Scaling Transfers Co-location, CDN, ... Reducing the browser's requests CSS sprites, expire headers, http compression... Optimizing the contents Defer loading, rearrangement, ... Efficient JavaScript development Improving the programming techs, ...
  • 15. Scaling Transfers Use CDN e.g., Akamai, Amazon S3, ... Pixnet experience: http://www.slideshare.net/gslin/using-cdn- to-improve-performance Reduce DNS Lookups Keep-Alive fewer domains Avoid Redirects Use Comet
  • 16. Scaling Transfers Sharding Dominant Domains browser HTTP/1.1 HTTP/1.0 IE6, 7 2 4 IE8 6 6 FF2 2 8 FF3 6 6 Saf 4 4 Chrome 6 6 Op 4 4 Connections per server
  • 18. HTTP Compression Modern browsers support HTTP compression -- to reduce the size of response content Gzip the static (html, css, js, ...) files Don't compress everything (e.g., jpg, png, pdf, ... they are already compressed) Check if the Accept-Encoding header has gzip or deflate value. Respond Content-Encoding: gzip header.
  • 19. HTTP Compression In Apache httpd server, use mod_gzip (httpd 1.3) or mod_deflate (httpd 2.x). [mod_deflate] AddOutputFilterByType DEFLATE text/html text/css application/x-javascript Problems: Proxy may cache uncompressed content Add Vary: Accept-Encoding header IE6 bug: Q312496, Q313712
  • 20. Make Fewer Requests CSS Sprites: Combine N icons into 1 bigger image. Reduce N requests info 1 request. Be careful of the arrangement of the icons sample: http://www.google.com.tw/images/nav_logo8.png tool: http://tw.spritegen.website-performance.org/ http://csssprites.com/ Combine CSS/JavaScript files Using Google Closure Compiler Apache: http://code.google.com/p/modconcat/ Lighttpd: http://code.google.com/p/lighttpd-mod-concat/ YUI Comobo Handler: http://yuiblog. com/blog/2008/07/16/combohandler/
  • 21. Make Fewer Requests Reduce Cookie size (or split domains) Inline images: using base64 encoding <img src="data:image/png;base64, xxxxx"> IE7/6 doesn't support this feature Useful in mobile browser Not only images: <frame src="data:text/html,%3Chtml%3E% 3Cbody%20style%3D%22background..."></frame>
  • 22. Using Expires Headers Use Expires header to tell the browser how long to keep the resource. Browser won't fetch the resource again until the expire time Apache mod_expires module can help setting expire time <FilesMatch ".(css|js|jpg|png)$"> ExpiresDefault "access plus 1 year" </FilesMatch> e.g., Expires: Fri, 25 Mar 2011 08:00:00 GMT Cache-Control header In stead of using a specified date, Cache-Control header shows HOW LONG the client should keep it e.g., Cache-Control: max-age=31536000 # cache 1 year
  • 23. Using Last-Modified Headers Use Last-Modified header to tell the browser the last modified time of the resource. [request] [request] GET /foo/bar.css HTTP/1.1 GET /foo/bar.css HTTP/1.1 .... ... If-Modified-Since: Thu, 25 Mar 2010 [response] 10:00:00 GMT HTTP/1.1 200 OK ... Content-Type: text/css Last-Modified: Thu, 25 Mar 2010 10: [response] 00:00 GMT+8 HTTP/1.1 304 Not Modified .... ... (empty response body)
  • 24. Configuring ETag ETag (Entity Tag) header tells browser which to cache How ETag works: read Wikipedia Problem: Not-the-same tag across different servers Apache: inode-size-timestamp IIS: timestamp:changenumber Solution: Set ETag manually Remove it. (in Apache) FileETag none
  • 25. Invalidates the Cached Resources If the static resources are cached, how to invalidate them? Use signature in filename ( /js/foo.AB32FDC.js ) Add query string ( /js/foo.js?20100325110000 )
  • 27. Minifying JavaScript Reduce the size of JavaScript files. Reduce the total response sizes. HTML, CSS files can be also compressed. Closure-compiler Web-based http://closure-compiler.appspot.com/ RESTful API http://code.google.com/closure/compiler/docs/api-ref.html Standalone executable Ofuscation Reduce the length of variables names Be careful the obfuscation method (e.g., eval cause performance degradation) Be careful the conflicts.
  • 28. Optimizing Images Using appropriate image format and remove redundant chunks in the image files. PNG8 (256 colors) is a good choice. Optimizing: Crushing PNGs pngcrush (http://pmt.sf.net/pngcrush/) Stripping JPEG metadata jpegtran (http://jpegclub.org/) Convert GIF to PNG ImageMagick Optimizing GIF animations gifsicle ( (http://www.lcdf.org/gifsicle/) Avoid image scaling
  • 29. Put Stylesheets on The Top Browser delays showing any visible components while it and user wait for the stylesheet at the bottom. Use <link> to include stylesheets @import MUST precede all other rules @import may cause blank white screen phenomenon (in IE)
  • 30. Put JavaScripts at The Bottom JavaScript blocks parallel downloads Put at top: the other components are delayed- loaded. defer attributes: Firefox still blocks other downloads
  • 31. Non-blocking Loading Scripts IE8 is the first browser that supports downloading scripts in parallel. Ways to load JavaScripts XHR Eval XHR Inject Script in iframe Inserting script DOM element document.write
  • 32. Non-blocking Loading Scripts Existing Busy Preserve Tech Parallel Diff Domain Scripts indicator Order Normal IE8, SF4 Y Y IE, SF4 IE, SF4 XHR Eval * N N SF, Ch XHR Injection * N Y SF, Ch Script in iframe * N N IE, FF, SF, Ch Script DOM * Y Y FF, SF, Ch FF, Op IE, SF4, Ch2, Script Defer Y Y * * FF3.1 IE, SF4, Ch2, document.write Y Y * * Op
  • 33. iframes iframes are heavy and block onload event. Use script DOM injection to insert ADs instead of iframes.
  • 35. Make JavaScript/CSS External Reusing components Cache the files Unobstrusive JavaScripts
  • 36. Simplifying CSS Selectors CSS selector policy: Rightmost-First Tips: Avoid * selector Don't qualify ID/CSS selectors Specific rules Avoid descendant selectors Avoid Tag > Child selectors Rely on inheritance
  • 37. Efficient JavaScript Tips Using className instead of modifying style attributes of a DOM element. [bad ] var foo = document.getElementById('foo'); foo.style.color = '#f00'; foo.style.fontWeight = 'bold'; [good] .highlight { color: #f00; font-weight: bold; } foo.className = 'highlight';
  • 38. Efficient JavaScript Tips (con'd) Appending a newly-created DOM element after modifying its attributes. (avoid reflows) [bad] var foo = document.createElement('div'); document.body.appendChild(foo); foo.innerHTML = 'Hello, world'; foo.className = 'hello'; [good] var foo = document.createElement('div'); foo.innerHTML = 'Hello, world'; foo.className = 'hello'; document.body.appendChild(foo);
  • 39. Efficient JavaScript Tips Using document fragment to create new contents. [bad] document.body.appendChild(createDivElement()); document.body.appendChild(createDivElement()); ... [good] var frag = document.createDocumentFragment(); frag.appendChild(createDivElement()); frag.appendChild(createDivElement()); .... document.body.appendChild(frag);
  • 40. Efficient JavaScript Tips Using array join instead of directly concatenate strings. [bad ] ] var a = 'Hel'; a += 'lo'; a += ', wor'; a += 'ld!'; [good] var buf = ['Hel']; buf.push('lo'); buf.push(', wor'); buf.push('ld!'); a = buf.join('');
  • 41. Efficient JavaScript Tips Faster trim method: (use simple regular expression) [bad] str.replace(/^s+|s+$/g, ''); [better] str.replace(/^s+/, '').replace(/^s+$/, ''); [much better] str = str.replace(/^s+/, ''); for (i = str.length - 1; i >=0; i--) { if (/S/.test(str.charAt(i))) { str = str.substring(0, i + 1); break; } }
  • 42. Efficient JavaScript Tips Use popular JavaScript frameworks. (e.g. jQuery)
  • 43. Misc.
  • 44. Responsive Web Applications Prefetching resources AJAX Avoid long-running scripts
  • 45. HTML5 http://whatwg.org/html5 Short tags: <!DOCTYPE html> <meta charset="UTF-8"> <script src="xxx.js">, <style>...</style> <script async ...> Application Cache (offline data) https://developer.mozilla.org/En/Offline_resources_in_Firefox http://www.whatwg.org/specs/web-apps/current- work/multipage/offline.html http://googlecode.blogspot.com/2009/04/gmail-for-mobile- html5-series-using.html WebStorage/WebDatabase API
  • 46. Mobile Web Mobile device has lower hardware-profile so that the web performance is more important! iPhone Safari/Android browser/Opera Mini likes HTML5 (w/ a little CSS3)
  • 48. Books High Performance Web Sites, O'Reilly Even Faster Web Sites
  • 49. Websites Let's Make the Web Faster (Google) http://code.google.com/speed Exceptional Performance (Yahoo!) http://developer.yahoo.com/performance/ High Performance Web Sites Blog http://www.stevesouders.com/blog/