Front-end techniques that reduce page weight and HTTP requests
Key Takeaway
Combine a storefront's CSS files into one file, then minify that file. Combining cuts the number of HTTP requests. Minification shrinks the file size.
Storefront speed drives online sales, because shoppers leave a site when finding a product and checking out takes too long. B2C Commerce best practices for front-end performance work in two ways. They shrink page weight, which is how many bytes a page downloads, or they cut the number of HTTP requests, which are the server calls a page needs to render.
Combined CSS and minification
A smaller file loads faster than its larger version, so a minified file loads faster than the original.
/* Before minification */
.product-tile {
margin: 0 auto;
padding: 12px;
border: 1px solid gray;
}
/* After minification */
.product-tile{margin:0 auto;padding:12px;border:1px solid gray}Both versions set the same styles. The minified version drops the line breaks, the indentation, and the extra spaces, so the file has fewer bytes to download.
Combined CSS reduces the number of CSS files a page uses. The page then makes fewer HTTP requests, so it loads faster.
Minification and combining solve different problems. Minification shrinks each file, while combining cuts the number of requests. So a storefront with several CSS files should do both: combine them into a single file, then minify it.
A sporting goods storefront loads five stylesheets on every page: base styles, the header, product tiles, the cart, and a seasonal banner. Each one is a separate CSS file, written with indentation and line breaks so developers can read it. The developer combines the five files into one CSS file, so the page makes fewer HTTP requests. Then the developer minifies the combined file, so the one file left is also smaller. Minifying alone would still leave five separate files. Combining alone would leave one file that still carries all its extra white space.