Web Performance Optimization PDF
Web Performance Optimization PDF
PRESENTATION TIER
PERFORMANCE OPTIMIZATION
Abstract
The performance of websites was always a critical non-functional
requirement. A better performing site directly translates into better user
experience, repeated site visits, and hence increased revenues. A fast
performing site invariably provides a competitive edge as well. Also these
sites are often indexed faster by search engines and often appear at the top
of search results8.
An ever increasing expectation for performance of websites means that Web
pages need to be designed to be optimal and fast rendering. Many a times,
websites lose their customers in a blink of an eye if they are a sub-second
slower than their competitors1
This white paper discusses this critical non-functional requirement, methods
to achieve it, and draws examples from various real-world scenarios. Most
of modern applications follow layered architecture mainly consisting of
three key Layers: presentation layer, business layer and integration layer. An
optimization approach invariably involves all the layers. This white paper
mainly focuses on the optimizations in the presentation layer.
Need for Speed the number of clicks and transactions design and development.
performed on the site, which would
Not long back even a 2-second page b. Top-down strategy: This is a reactive
eventually result in the loss of users2.
strategy which involves doing a
response time was considered as an
post-mortem of pages when any
acceptable one. However, web users have
become increasingly impatient when Strategies of presentation performance issue is discovered.
This involves analysing the page
it comes to speed these days. Earlier, layer performance
components and targeting the
speed was considered a feature and now optimization
optimizations which reap big and
it is deemed a necessity. Additionally, There are broadly two main categories quick benefits and iteratively enhance
technological innovation in mobile space adopted for performance optimization: other components. This is potentially
has raised the bar for speed. Hence, speed costly and the cost mainly depends
a. Bottom-up strategy: This involves
makes a lot of economic sense now. on the phase during which the issue is
carefully laying out the ground rules
A recent research found that 250-450 uncovered.
for performance based on required
milliseconds are the magical numbers SLAs and design / develop the pages Subsequent sections discuss these
that decide the winner in the race of by adopting the principles laid out. This strategies in detail.
web speed . Research also indicates that
1 is the preferred approach that involves
the slower the site, the lesser would be optimization in both presentation layer
2. Execute the performance principles by identifying the key pages/transactions and optimizing them
The performance service level i. Page render time across different geographies
agreement (SLA) the organization
has promised to its customers : ii. Overall transaction time for key processes.
i. Richness involves providing feature rich client-side components like widgets and
Making the user interface rich as pages with high degree of intuitiveness
well as responsive: ii. Responsiveness and interactivity involves making those client-side components
highly interactive by adopting techniques like partial-page-rendering.
iv. Avoid 3rd party plugins unless absolutely required. Even when they are included, only
load the scripts on-demand and keep the 3rd party scripts at the bottom of the page.
ii. Appropriate positioning of the files to improve the perceived page load time for user.
Optimizing static assets like iii. Use PNG format of image always
images, JavaScript, CSS, JSON
which involves iv. Encouraging usage of CSS sprites
i. Understand the key application expectation from end uses by conducting usability
studies, surveys, interviews and A/B testing. Once the key expectations are
understood design performance strategies around these expectations
Heighten the user experience of ii. Adopt process improvements such as:
key business processes: 1. Reduce number of steps/pages for completing the overall process
Provide interactivity through usage of i. Wherever possible, employ partial page rendering to avoid the full page refresh.
client-side components:
ii. Adopt client-side validation framework to catch the errors
Provide intuitive information architecture i. Providing optimized search functionality on all pages to reach any page using
and easy navigation after careful and keyword search
thorough research of key functionalities.
This involves things like: ii. Providing elaborate menu to allow the user to navigate to any sub level page.
ii. Remember user’s preferences to customize the key functionalities such as search, navigation
Enhance user overall experience by
leveraging client-side components: iii. Recommendations based on transaction history
iv. Leverage web analytics to gain insights into customer’s implicit preferences and use it for
further customizations
i. Wherever possible load the data only on-demand instead of pre-loading all the data. For
instance:
On-demand data loading:
1. Use pagination for search results and load the second page only when requested
2. Information in the popup can be loaded only when user clicks on popup link.
i. Come up with process for automating and make it part of process. For instance merging and
minification can be automated and added to the build process
ii. Identify all the tools which help in automation and optimization to improve productivity
1. Use tools like Google PageSpeed, Yahoo YSlow etc. for constantly checking the page
Identify areas for automation:
performance.
2. Use tools like Gomez for identifying page performance across geographies.
3. Identify Web analytics tools for automatically tracking the user activities and page
performance.
Avoid chatty service calls i. Minimize the service calls from presentation tier
Encourage asynchronous calls i. Wherever possible promote asynchronous calls between presentation tier and
business tier.
Normally performance optimization is a multi-layer (presentation layer, business layer, database layer etc.) and multi-team (UI developers,
business logic developers, networking team, and Infrastructure team) effort. This paper primarily addresses the concerns related to the
presentation layer.
• Inclusion of multiple JavaScript libraries which build the UI modules and impart
interactive behaviour. This increases resource requests for a page.
Rich and Intuitive User interface using
• Inclusion of multiple CSS files for adding styles for the UI modules. This increases
client side modules resource requests for a page.
• Including the JS files at the top of the page which blocks the loading of subsequent page
components.
Integration with 3rd party functionalities • Include lots of plugins like Twitter, Facebook, Google+, and LinkedIn etc.
• Include JS files required for site survey at the beginning of the page
Adding large marquee images / animated • Multiple images increases the resource requests
flash objects/videos on each page
• Bigger the asset size, larger would be the bandwidth consumption
Security requirements preventing usage of • Absence of client-side page components forces the user to load the full page for each
client-side components functionality. This would increase the overall time taken for completing a transaction.
Enable mobile access • Absence of device specific site and mobile accelerator would render the page slow in
mobile devices
Merge all the JS and CSS files • Minimize the total number of resource requests. • YUI
• Network round trip for additional resource trip is avoided
Asset Placement: • As JS files are at the bottom of the page, it will not block the NA
• Place all external JavaScript links at serial load of the page. This would decrease the perceived
load time for the user. Many times 3rd scripts related to
the bottom
analytics and others has the potential to slow down the entire
• Place all CSS file links in the head site. Hence placing them at the bottom would eliminate this
element problem
Assets Optimization
• Results in multi-fold benefits such as reducing the number or • Smushit Image
• Use CSS sprites resource requests and reduced image size compressor
• Use lossless compression or PNG • Image compression would decrease the size by approximately • Trimage
files 25%
Compression • Absence of device specific site and mobile accelerator would • Content-Encoding
• Enable gzip compression for HTTP render the page slow in mobile devices header
traffic
Choose appropriate presentation • Use the JavaScript library which is enough to satisfy
components application requirements.
CDN caching
Sometimes clients will be having performance specific requirement for each geography. Let’s say that we would like to render a
normal page across all geographies when the origin server is in the US, then even with fully cached and an optimized site, it would
be challenging to render the page within 2 seconds in the Asia Pacific region.
In such scenarios it is worth considering the Content Delivery Network (CDN)/Edge caching like Akamai, Amazon CloudFront.
CDN systems would cache assets like images/Videos/JS/CSS and would serve the content from geographically optimal location to
accelerate the page rendering.
22.8
41 30.30 33.00
20.1
10.8 6 30.30
4.00
JS (935KB)
JS (12s)
CSS (827)
CSS (10s)
Image (273KB)
Image (1s)
Server resp (443 KB)
Server resp (9.8s)
Xhr
• The performance optimization was an • Server side caching and connection number of portlets on a dashboard
after-thought rather than a bottoms-up pool was recommended. page. The optimal size of portlets on a
page is between five to eight.
approach.
• Batching of services call was
• The creative agency had missed the recommended to reduce the round
4. Results
performance optimizations for the trips to services layer.
delivered web artifacts that includes a. Page load times improved to
HTML, JS, and CSS etc. acceptable levels of 10 seconds
Statistics The page has a total of 65 HTTP requests and a total weight of 1005.7K bytes with empty cache
WEIGHT GRAPHS
• The CSS and JS files were not minified (?) b. Presentation layer:
all geographies
• Partial page rendering was not adapted page load times across varied to 81%, a major chunk of contribution
to the fullest extent. geographies. came from performance improvements
in HTTPS pages and client side
• AJAX based client side modules were
modules.
3. Performance Optimization Exercise suggested for key functionalities like
Following were the recommendations search, product finder to enhance user
made: experience
Statistics The page has a total of 48 HTTP requests and a total weight of 1024.2K bytes with empty cache
WEIGHT GRAPHS
1. Context and Analysis a. Business layer: • A CDN network like Akamai was
• Supplier and distributor portals • Batch the database calls and use
recommended to maintain acceptable
were taking about 25 seconds in the page load times across geographies.
Hibernate caching, lazy loading to
production environment. enhance the database operations. • AJAX based client side modules were
• Much of the page load time was spent • Use on-demand pagination instead of
suggested for key functionalities
in server calls and loading heavy static like pagination and dashboard
pre-fetching a large result set.
assets. functionalities.
• Rewrite the queries to use the database
• The database access layer consisting of indexes for faster performance. 4. Results
Hibernate was not optimized.
• Use optimal application server • Page load time reduced to within 10
parameters related to thread and seconds.
2. Root cause
database connection pool.
• Web components were not optimized
using performance best practices. b. Presentation layer:
• Server side code was not optimized • All the performance optimizations
recommended in the performance
3. Performance Optimization optimizations table (merging and
Exercise minification, asset placement, browser
Following were the recommendations caching etc.) was recommended.
made:
One would start with the critical performance optimizations that would result in major benefits in the initial iteration and involve the
remaining ones in subsequent iterations.
Following chart depicts the key performance optimizations and the performance gains that can be realized:
Ease of implementation
Performance gain
Following are the high level steps involved in top-down performance optimization:
1. Analyse the factors contributing to the page performance. We can use tools like PageSpeed, YSlow for performing this operation.
2. Start optimizing the activities which would realize maximum performance improvements. Above chart provides a guideline for this step
Note:
1. The application design and the time available limits the performance optimization options in this strategy. For instance if the complete
application is developed without any client-side components, then developing client-side widgets would potentially involve major
application framework changes leading to higher development and testing times.
2. Application domain requirements need to be kept in mind while performing this step. For instance if security requirements don’t permit
usage of client-side components, then all optimizations related to that would not be applicable.
2. CDN networks also have modules Security vs. Speed 1. HTML 5 offers a whole array of features
which would speed up the delivery for While building financial sites, there could related to performance optimization.
SSL sites. Consider employing them. For be instances wherein the performance This includes hardware acceleration
instance Akamai offers secure content principles cannot be fully applied due to support for graphics and video
delivery. security constraints. For example:
2. Offline web apps features in HTML
Additionally, we can also consider using • The financial firm has restriction 5 can be leveraged to serve static
hardware SSL accelerators like that of Blue for using client-side modules and informational content.
Coat and Coyote Point. functionalities.
Shailesh Shivakumar
is a Technology Architect with the Manufacturing unit at Infosys. He has over 10 years of industry experience. His areas of expertise
include Java Enterprise technologies, portal technologies, User interface components and performance optimization.
© 2018 Infosys Limited, Bengaluru, India. All Rights Reserved. Infosys believes the information in this document is accurate as of its publication date; such information is subject to change without notice. Infosys
acknowledges the proprietary rights of other companies to the trademarks, product names and such other intellectual property rights mentioned in this document. Except as expressly permitted, neither this
documentation nor any part of it may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, printing, photocopying, recording or otherwise, without the
prior permission of Infosys Limited and/ or any named intellectual property rights holders under this document.