Alexander Haneng
Jul 15, 2014
  5261
(1 votes)

EPiServer CMS Site Performance Part 3: Optimizing images and using sprites

In the last post we looked at bundling and minifying JavaScript and CSS files on the demo site. This time we will take a look at the image files.

Web Essentials
The Web Essentials extension to Visual Studio is as the name says essential. If you haven’t already, you need to download it now

Optimizing images
Most often you will find that you can make image files even smaller without decreasing the image quality. With Web Essentials installed it is simply a matter of right clicking the image(s) in Visual Studio and select “Web Essentials –> Optimize images”.

optimizepngs

The optimization shrank the file sizes between 3% to 95%. Here is one example:
Optimized triangle.png
Before: 3061 bytes
After: 303 bytes
Saving: 2758 bytes / 90,1%

Creating sprites
If you look in the header area of the demo site you will see that we have five share icons, each consisting of its own small image. 

image

<ul class="follow_icon"> <li><a href="#"><img src="/img/follow_icon1.png" alt=""></a></li> <li><a href="#"><img src="/img/follow_icon2.png" alt=""></a></li> <li><a href="#"><img src="/img/follow_icon3.png" alt=""></a></li> <li><a href="#"><img src="/img/follow_icon4.png" alt=""></a></li> <li><a href="#"><img src="/img/follow_icon5.png" alt=""></a></li> </ul>

One way to reduce the number of requests is to combine these five images into one sprite, and then use CSS to only show the part we need. To create the sprite we select the five images in Visual Studio, right click and select “Web Essentials –> Create image sprite…”.

createsprite

This is what the sprite looks like:

FollowSprite

Not only will Web Essentials create a new image sprite file, but also the CSS code you need to use the sprite (as well as LESS and SASS code). All we have to do is to copy the CSS code to our style sheet and modify our HTML to use the sprite.

image

<ul class="follow_icon"> <li><a href="#"><div class="img-follow_icon1"></div></a></li> <li><a href="#"><div class="img-follow_icon2"></div></a></li> <li><a href="#"><div class="img-follow_icon3"></div></a></li> <li><a href="#"><div class="img-follow_icon4"></div></a></li> <li><a href="#"><div class="img-follow_icon5"></div></a></li> </ul>

Result
Lets run YSlow again and see what impact our image optimizations have had.

image

Bytes transferred: 287.1KB down from 326.5KB (Step 1: 333.3KB)
Requests: 26 down from 30 (Step 1: 35)
Time: 1.09 seconds down from 1.16 seconds (Step 1: 1.27 seconds)

Jul 15, 2014

Comments

Henrik Fransas
Henrik Fransas Apr 15, 2015 04:56 PM

Where are the CDN part :-)

Please login to comment.
Latest blogs
Creating an Optimizely CMS Addon - Adding an Editor Interface Gadget

In   Part One   of this series, I covered getting started with creating your own AddOn for Optimizely CMS 12. This covered what I consider to be an...

Mark Stott | Aug 30, 2024

Configure your own Search & Navigation timeouts

The main blog Configure your own Search & Navigation timeouts was posted for years but you need copy the code to your application. We now bring tho...

Manh Nguyen | Aug 30, 2024

Joining the Optimizely MVP Program

Andy Blyth has been honoured as an Optimizely MVP, recognising his contributions to the Optimizely community. Learn how this achievement will enhan...

Andy Blyth | Aug 29, 2024 | Syndicated blog

Welcome 2024 Summer OMVPs

Hello, Optimizely community! We are thrilled to announce and welcome the newest members to the Optimizely Most Valuable Professionals (OMVP) progra...

Patrick Lam | Aug 29, 2024

Create custom folder type in Edit Mode

Content Folders, which are located in assets pane gadget or multichannel content gadget, allow you to add any type of block or folders. But...

Grzegorz Wiecheć | Aug 28, 2024 | Syndicated blog

Creating an Optimizely AddOn - Getting Started

When Optimizely CMS 12 was launched in the summer of 2021, I created my first AddOn for Optimizely CMS and talked about some of the lessons I learn...

Mark Stott | Aug 28, 2024