Lecture 14
Lecture 14
• it’s no surprise that many sites deliver the same page weight or additional
page weight to mobile devices without the designers and developers even
realizing it..
• Many creators of responsive sites are already going above and beyond in
more.
Tools like Adaptive Images detect your user’s screen size and
will automatically create, cache, and deliver correctly sized
images based on your defined breakpoints
For example, simply setting display: none to an element will not prevent a browser from
downloading the image:
<div id="hide">
<img src="image.jpg" alt="Image" />
</div>
/* Seriously, don't do this.
Browsers will still download the image. */
<div id="hide"></div>
/* Again, don't do this.
Browsers will still download the image. */
#hide {
background: url(image.jpg);
}
<div id="parent">
<div></div>
</div>
/* Hide the parent element;
Browsers will not download the image. */
#parent div {
background: url(image.jpg);
}
<div id="match"></div>
@media (min-width: 601px) {
#match {
background: url(big.jpg);
}
}
<div id="match"></div>
#match {
background: url(regular.png);
}
<picture>
<source media="(min-width: 800px)" srcset="big.png">
<source media="(min-width: 400px)" srcset="small.png">
<img src="small.png" alt="Description">
</picture>
Check out how amazing this is. Not only are we able to match media attributes to tell the browser which image
file to download, but we also have a low-resolution image that will be downloaded by browsers that don’t
support the picture element. Picturefill is a polyfill that enables support for the picture element in browsers that
don’t currently support it
You can use the picture element to serve retina images when applicable, too!
<picture>
<source media="(min-width: 800px)"
srcset="big.png 1x, big-hd.png 2x">
<source media="(min-width: 600px)"
srcset="medium.png 1x, medium-hd.png 2x">
<img src="small.png" srcset="small-hd.png 2x"
alt="Description">
</picture>
In this example, srcset tells the browser which image to choose at different pixel densities.
Again, we’re saving overhead for our users by being precise and telling the browser exactly
which single image file is the right one to retrieve and display.
Fonts
• Font files can add a huge amount of overhead to your site because they
require additional requests and increase page weight. As discussed in
“Optimizing Web Fonts,” there are several ways of optimizing your
font files to ensure they are as high performing as possible. One
additional consideration you can make in your responsive design is to
load your custom font file only on larger screens. This is something
we do at Etsy, as we would rather save our users from downloading
the extra font file overhead if they’re on a mobile device.
To do this, set your normal fallback fonts on your content. Then
use a media query to only apply your web font to content at a
large breakpoint:
@font-face {
font-family: 'FontName';
src: url('fontname.woff') format('woff');
}
This will download and apply the font file only if the user’s
device matches the media query. All browsers (except Internet
body {
Explorer 8 and lower) are smart about downloading a font file
font-family: Georgia, serif; only if it applies. Internet Explorer 8 and lower will download all
} @font-face files referenced in a page’s CSS file, even if they
aren’t used on the page.
@media (min-width: 1000px) {
body {
font-family: 'FontName', Georgia, serif;
}
}
Approaches
• While you’ll make many decisions about how to create your site’s
responsive web design during the actual design and development
process, it’s important to take a beat before you begin any work to
consider your overall approach and how it will impact performance.
Building performance into project documentation, taking the time to
look at your site from a mobile-first perspective, and figuring out how
you’re going to measure the performance of your site across media
queries will help you to create a speedy, responsively designed site.
Project Documentation
A mobile-first approach to designing any site will help you in so many areas.
It will prompt you to:
• Ask critical questions up front (“What is the core purpose of this page?”).
• Identify the most important functionality and content for your users.
• Establish design patterns and how they will change across screen sizes.
• Think about your site from an accessibility perspective (“How accessible
will this be for people on slower connections or less capable devices?”).
• You can progressively enhance your site by adding functionality,
incorporating more powerful animations and styles, and taking
advantage of newer devices’ capabilities, all while keeping track of
performance implications as you add on.
Performance is a crucial aspect of responsive web design. When
• If you’re able to, implement automated tests that measure the total
page weight for each of your chosen breakpoints. Tom Barker
included an excellent chapter on continuous web performance testing
in his book High Performance Responsive Design, which outlines how
to implement Phantom JS tests that measure each breakpoint’s
performance, including YSlow score and total page weight.
• You can also test this manually. Emulate a device using Chrome
DevTools and use the Resources panel to see which image size is
being downloaded for that device. Here is an example set of media
queries in which I choose to serve a different image based on
breakpoint:
1. User Experience: Performance directly impacts user experience. A slow-loading website can frustrate users and drive them
away, leading to higher bounce rates and lower engagement. Responsive design aims to provide a seamless experience
across devices, and performance plays a vital role in ensuring that experience remains smooth and consistent.
2. Mobile Optimization: With the increasing use of mobile devices for browsing the web, optimizing performance is even
more critical in responsive design. Mobile networks may have slower speeds and higher latency compared to desktop
connections. Designing with performance in mind ensures that the website loads quickly and functions smoothly on mobile
devices, enhancing the overall user experience.
3. SEO Impact: Website performance is a significant factor in search engine rankings. Search engines like Google consider
page load times as part of their ranking algorithm. A responsive website that loads quickly across all devices is more likely
to rank higher in search results, driving more organic traffic to the site.
4. Conversion Rates: Studies have shown that faster-loading websites tend to have higher conversion rates. By optimizing
performance in responsive design, you can increase the likelihood of users completing desired actions such as making a
purchase, signing up for a newsletter, or filling out a form.
5. Bandwidth Considerations: Responsive design involves serving the same content to users across various devices.
Optimizing performance helps minimize the amount of data transferred, reducing bandwidth usage and potentially lowering
hosting costs.
6. Progressive Enhancement and Graceful Degradation: Performance considerations often lead to the adoption of principles
like progressive enhancement and graceful degradation. These approaches ensure that the website functions well across
different devices and network conditions by providing a baseline experience that can be enhanced for more capable devices
or scaled back for less capable ones.
Incorporating performance considerations into the design process of a
responsive website involves various strategies such as optimizing
images, minimizing HTTP requests, leveraging browser caching, using
responsive images and fonts, and employing techniques like lazy
loading and asynchronous loading of resources. By treating
performance as a design consideration from the outset, designers can
create responsive websites that not only look great but also provide fast
and efficient user experiences across all devices.
• https://mantisbt.org/demo.php