educational

Sipping on a Sprite to Boost Site Performance

Webmasters and designers seeking ways of speeding up the perceived load time of their websites have a powerful tool at their disposal: CSS sprites — a well-proven way to boost website performance.

While frequently overlooked, the use of CSS sprites is nothing new and as such may represent a significant opportunity for those operators focusing on website optimization.

The use of CSS sprites is nothing new and as such may represent a significant opportunity for those operators focusing on website optimization.

Let us take a closer look:

For the uninitiated, a CSS sprite is nothing more than a master image composed of multiple images; with cascading style sheets used to determine the positioning of those component images. For example, a website that offers emoticons could use a different graphic for a smile and a separate image to frown — along with numerous other images that signify a range of user emotions. Combining these multiple images into a single CSS image sprite could give a tremendous boost to web pageloading performance.

The reason for this is that each image requires a separate call from the web page to the web server, with the round-trip processing delays often accounting for more than 80 percent of a page’s load time.

While this reasoning applies equally well to “photo” images as it does to page graphics, navigational images, emoticons, backgrounds and more, the file size of the sprite image also needs to be considered. For example, a dozen thumbnails from an image gallery are combinable into a sprite, but the full-size photos they link to should likely remain separate images, in order to avoid a multi-megabyte download.

To use sprites, you must first select the desired individual images and then combine them on to a base graphic — transparent PNG base images are typically used — that is large enough to accommodate the total pixel size of the individual images. For example, two 25x25-pixel images are combinable into a single 25x50-pixel sprite, a task readily performed in Adobe Photoshop, for instance.

For a hands-on example, try one of the many online sprite generators, such as www.csssprites.com.

As a test of this particular generator, three emoticons combined to generate a single sprite, with the resulting sprite PNG and enabling HTML code displayed, along with usage examples. The code is below:

.parent-element { background:url (result.png); }

To use image number one, add “background-position: 0px 0px;” for number two, the line changes to “background-position: 0px –28px;” and for number three, “background-position: 0px –53px;” — here, the horizontal width of all images remains the same, but the vertical positioning value changes to fully reveal the proper portion of the image. It is important to note that the parent element needs to be the same size as the displayed image. Enable linkable images by layering a transparent spacer PNG over the background, setting the spacer’s height and width in CSS.

An easy way to understand the process is to think of a CSS sprite as a book, with each image a page — if someone tells you to “turn to page 27,” you will see the content of page 27. Likewise, telling a web browser essentially to “turn the sprite to page 27,” will reveal the appropriate image. You did not load 27 images, just a single book, and then turned the page…

It sounds much harder to do than it really is and the benefits are quick and tangible. Try it yourself!

Related:  

Copyright © 2024 Adnet Media. All Rights Reserved. XBIZ is a trademark of Adnet Media.
Reproduction in whole or in part in any form or medium without express written permission is prohibited.

More Articles

opinion

The Search for Perfection in Your Payments Page

There has been a lot of talk about changes to cross sales and checkout pages. You have likely noticed that acquirers are now actively pushing back on allowing merchants to offer a negative option, upsell or any cross sales on payment pages.

Cathy Beardsley ·
opinion

Unpacking the Payment Card Industry's Latest Data Security Standard

The Payment Card Industry Data Security Standard (PCI DSS) is a set of requirements and guidelines that apply to all businesses that accept credit card payments, and is designed to ensure the security of those transactions.

Jonathan Corona ·
opinion

Compliance With State Age Verification Laws

During the past year, website operators have faced a slew of new state age verification laws entailing a variety of inconsistent compliance obligations.

Lawrence Walters ·
opinion

Merchants in Spotlight With Visa's VIRP

By now, most merchants know about the Visa Integrity Risk Program (VIRP) rolled out in spring 2023. The program is designed to ensure that acquirers and their designated agents — payment facilitators, independent sales organizations and wallets — maintain proper controls and oversight to prevent illegal transactions from entering the Visa payment system.

Cathy Beardsley ·
opinion

How to Know When Hosting Upgrades Are Really Needed

I was reminded about an annoyingly common experience that often frustrates website owners: upgrades. Sometimes, an upgrade of physical system resources like CPU, RAM or storage really is required to solve a problem or improve performance… but how do you know you’re not just being upsold?

Brad Mitchell ·
profile

WIA Profile: Natasha Inamorata

Natasha Inamorata was just a kid when she first picked up a disposable camera. She quickly became enamored with it and continued to shoot with whatever equipment she could afford. In her teens, she saved enough money to purchase a digital Canon ELPH, began taking portraits of her friends, shot an entire wedding on a point-and-shoot camera and edited the photos with Picnik.

Women in Adult ·
trends

Collab Nation: Top Creators Share Best Practices for Fruitful Co-Shoots

One of the fastest ways for creators to gain new subscribers and buyers, not to mention monetize their existing fan base, is to collaborate with other creators. The extra star power can multiply potential earnings, broaden brand reach and boost a creator’s reputation in the community.

Alejandro Freixes ·
opinion

Bridging Generational Divides in Payment Preferences

While Baby Boomers and Gen Xers tend to be most comfortable with the traditional payment methods to which they are accustomed, like cash and credit cards, the younger cohorts — Millennials and Gen Z — have veered sharply toward digital-first payment solutions.

Jonathan Corona ·
opinion

Legal and Business Safety for Creators at Trade Shows

As I write this, I am preparing to attend XBIZ Miami, which reminds me of attending my first trade show 20 years ago. Since then, I have met thousands of people from all over the world who were doing business — or seeking to do business — in the adult industry.

Corey D. Silverstein ·
opinion

Adding AI to Your Company's Tech Toolbox

Artificial intelligence is all the rage. Not only is AI all over the headlines, it is also top of mind for many company leadership teams, who find themselves asking, “How can this new tool help our company?”

Cathy Beardsley ·
Show More