One of the most fundamental strategies for optimizing website load time is to minimize the quantity of data that has to be downloaded by the user's web browser. Minimizing both the number and size of file resources will keep pages loading as quickly and efficiently as possible.
An easy way to start trimming down page weight is to remove old, out of date, unused or unnecessary code and other resources. This could mean entire files, but it may also include sections of code within files. It can also mean files that are used on some pages but not on others, so in some cases removing files on a page-by-page basis can have a worthwhile impact.
Templates & Frameworks
Clearing out unused files and code can be particularly effective for websites that use a template like a WordPress theme or a front end framework like Bootstrap. Websites built on these systems often only use a portion of the available modules, features and options, so removing unused code can go a long way to reduce file sizes.
Here's a snippet of CSS code with comments and formatting for legibility:
And the 'minified' version:
Each of these code snippets have the same meaning and produce the same result in the web browser, but the minified version produces a smaller file. Applying this effect over hundreds or thousands of line of code can yield significantly smaller files.
Note that reducing file size by minifying code content is different from HTTP file compression which is applied by the web server before files are transferred or image compression which is applied as a part of image optimization.
Files should be consolidated in a way that makes sense for the context, striking a balance between fewer, larger files and only loading resources that are used on a given page. For example, CSS styles for elements common to all pages like the header, footer and navigation could be combined into one file, while keeping styles for pages types like blog posts or product pages in separate files and only loaded where needed.
Given the limitations in the way web servers and web browsers interact, best practice has long maintained that files should be consolidated as much as possible to minimize the impact of network latency by reducing individual requests from the web server. The growing adoption of HTTP/2 and its ability to load many files simultaneously (rather than one or a few at a time) effectively eliminates that practice as a goal in itself.
In short, consolidate files logically and to a reasonable extent, combining related files by how and where they're used.
A great website design strengthens the impact of it's message and unique, stylish fonts can add a valuable layer of visual interest. Largely due to simplified methods for adding fonts to websites, custom fonts have become very common across the web and it can be tempting to use fonts too liberally.
Best In Moderation
Custom fonts can be a great design enhancement, but with the benefit comes the performance trade off and potential load time pitfalls. Until variable fonts become more standard, each additional font or font style means an additional file, so shrewd choices about which fonts really make an impact and which can be omitted will reduce page weight - usually with little to no negative effect on overall user experience.
Although the size of the needed files varies between fonts, a good rule is to use one font for headings and one for regular paragraph text, with a sensible limit of four or five total font variants. For example, one font for (1) general paragraph text plus (2) bold and (3) italic styles, with another font for (4) headings and other distinctive text elements.
As an optional strategy to further reduce the number of fonts loaded on mobile devices, custom fonts can be limited to larger screens (or other conditions) with CSS media queries. Web browsers won't load font files that don't apply to a given device, conserving that page weight.
With custom fonts so commonplace, it's easy to forget that they don't have to be used at all. They can also be used selectively, like a special custom font for headings but a common system font for general paragraph text.
Sometimes called web safe fonts, system fonts are already a part of the user's device software and ready to use without downloading. A list of fonts can be specified in the CSS code - often called a font stack - that the browser will use depending on what fonts are available on a given device.
While approapriately-licensed font files can be self hosted, web font services leverage the power of CDNs and include options like custom character sets. Google Fonts is the most widely used, but there are other similar services.
One of the benefits of third-party web font services is that the font files may have already been downloaded by the user's browser during a visit to another website. The browser saves those files and uses them on other websites without downloading them again.
Font services also offer the option to load only the specific characters needed, rather than the full font file. This is a clever way to save page weight when only a few specific characters, words or phrases of a special font are needed.
Fonts from web font services are most commonly added to a website with a
<link> reference in the HTML. (An
@import rule in CSS works as well, but generally results in poorer performance for third-party fonts.) Here's an example of loading two variants of a font called Roboto from Google Fonts:
Up next:Optimize Images