How do you reduce website bloat?

Why is my website slow? It is a common question developers, designers, bloggers and even your visitors ask. No website is immune from having speed issues.

How Do You Reduce Website Bloat
Photo by Farzad Nazifi on Unsplash

What causes website bloat?

How you designed and built the site affects its speed. Things like images, videos, CSS and code can impact your site. Even your server can affect how the site performs.

What can you do to speed up your site?

1. Optimize your images

You may be using images created in file formats that aren’t designed for the web. They may be large in file size as well. You can use an optimize tool to shrink the file size down without noticeable loss in quality. When you optimize an image, it loads faster on your site.

2. Get rid of unnecessary images

Check your web server for unused images. Unused images can affect user experience and performance of your site. If you aren’t using these images, delete them off your server. WordPress users can clean up their images using plugins or manually. If you have Windows, you can use Powershell to find and remove used images.

3. Optimize your videos and other files

Large files can slow a web site down. Files like videos or PDFs get quite large. You can optimize them before uploading. For PDFS, you can use Adobe Acrobot Pro’s PDF Optimizer to make them faster for the web. With videos, you can use a video hosting service like Vimeo or YouTube to host your videos. Then, you can embed them on your page.

4. Optimize your CSS

CSS files can get large and unruly after a while. Optimizing and managing them can be a challenge. It can be hard to find unused styles. You can use a tool like Helium CSS to find them. By getting rid of unused styles, you can reduce the size of your CSS.
Some of your styles are used more often than others. Print styles are used when a page is printed. You may want to separate them into their own file. With frequently used CSS, you may want to consider using inline styles instead. Before uploading your CSS, you can use a minifier to reduce the amount of whitespace it uses.

5. Check your code for speed issues

Are you using old code? If you are, you may need to rewrite, refactor or even replace it. Look at older code and decide if you need to keep it. If not, remove it.

6. Review the content of your page.

You may have too many items on your page. Do you have old or outdated content? If so, you can remove them. Review the rest of the items on the page to see if you can remove some content and still achieve the same goals of the page.

Summary

Preventing website bloat can be a full time job. By changing your development process to include optimization. You can prevent it from getting slow.

Getting Started with CSS Variables

What are CSS Variables?

Most programming languages allow you to use variables. Variables are used to store information and manipulated by the program. In CSS, you previously need a preprocessor like SASS or LESS to use variables. CSS Variables are custom properties that you define with specific values and reuse throughout your CSS document.

Getting Started with CSS Variables
Photo by Pexels from Pixabay

In CSS as well as programming languages, you can declare your variables either globally or locally. A global variable is a custom property that is available to your entire HTML document. To declare a global custom property, you use the :root pseudo-class.

For example, you want to define your theme colors. You can use the :root pseudo-class to do that.


:root {
    --main-color: blue;
    --main-text-color: aqua;
}

You can also declare a variable locally. By declaring a custom property locally, you limit the scope or impact that the variable can have.


.primary-background-color {
    --background-color: teal;
}

When you create a CSS Variable, you can overwrite the value. By taking advantage of cascade, you can create a new style that changes the default value of a global declare variable.


.text-color {
    --main-text-color: orange;
}

Var()

Preprocessors allow you to use a variable by referencing its name. You use the Var() function when inserting the value of a custom property.


.featured-content-box {
    background-color: var(--main-color)
}

Calc()

Sometimes you need to do a little math to get your styles to work they way you want them to. Calc() is a native CSS way to do simple math calculations. With it, you can do addition, subtraction, multiplication and division. CSS Tricks talks about use cases for Calc().

For example, you may want to change the width of a style.


.box {
    width: calc(100% - 80px);
}

Why use?

CSS Variables can be overwritten, cascade down and used in JavaScript. If you don’t want to use a preprocessor like SASS or LESS, you can use custom variables to make managing your styles a lot simpler.

In Web Dev Simplified’s CSS Variables Tutorial, he gives you a quick introduction on how to use them. You learn what they are, how to write them and use them with JavaScript.

Summary

At first, CSS Variables sounds complicated. They can help you to make your CSS easier to maintain. Variables are a lot easier to use than hex or hsl codes.

How do you fix problems in print CSS?

A print stylesheet allows you to print a webpage. Testing a print stylesheet can be challenging. You create print styles to manage how the page prints, but it still doesn’t look right. What do you do when you need to fix or find a problem that occurs when the page is printed?

How Do You Fix Problems In Print CSS
Photo by Fernando Arcos from Pexels

You have two options use the Print Preview or the browser’s developer tools.

Print Preview lets you see how your web page looks on the printed page. You can see which elements to hide like navigation bars, footers or certain images. It also helps you to identify simple problems. Problems like large text, too much space between elements and extra styling that may use too much ink.

What do you do when you can’t find the source of a problem? Use your browser. Chrome, FireFox and Safari allow you to display print styles directly in your browser. This option is great for seeing how your design looks without print the page out. You can use the inspector to diagnose issues with your CSS. It can help you identify design issues that need a print style either created or modified.

For example, I had an app that printed a receipt. It printed on two pages instead of one. First, I used the Print Preview to find out what elements to hide when printed. After that, I saw that it was still printing on two pages. I couldn’t see what was causing the issue.

I changed the Developer Tools to show the print CSS. When I used this option to view the receipt with the print styles, I found the source of the problem. The problem was in the footer. I started to look at the styles for it. The footer had a height of 10.75 ems. I experimented by turning off the height. It changed from printing on one page instead of two. To fix this issue, I added a new print style for the footer and made the height auto. When I looked in print preview, it printed an one page.

Completing a Pricing Plan Coding Challenge

I found Frontend Mentor where you can improve your front-end coding skills by building real projects. You can pick a challenge that appeals to you. Then, download the design documents, images and other assets that you need.

Pricing Plan Coding Challenge

Pricing Component With Toggle

The challenge I chose was the pricing component with toggle. It has three options: Basic, Professional and Master. You have to use a toggle switch to show the prices for Annually or Monthly.

How I Built It

I built it using HTML, Bootstrap and JavaScript. With Bootstrap, I had to override some of its styles to get rid of the column margin and create custom styles for the button.

I wrote JavaScript that watches for when the toggle is selected. When you open the page, it defaults to monthly pricing. If you select Annually, you see the Annual prices. When you select Monthly, it switches back to Monthly prices.

What I Learned

The style guide defined colors in HSL and included a linear gradient. The linear-gradient is a CSS function that allows you to create a transition between two or more colors along a straight line. You can choose the direction or angle of the transition. For two of the buttons and toggle, the gradient moves from left to right. The professional plan card moves from top to bottom.

I used two structural pseudo-classes in CSS to create the design. The :first-of-type and :last-of-type selectors allow you to target the first and last occurrence of an element in a container.

Bootstrap has a toggle switch available. It was not customizable with CSS. You have to compile custom Bootstrap in order to change how it looks. I found CSS toggle solution that works like the design. I modified it to work with my CSS.

Frontend Mentor asks developers to post their solutions to their site. If you get stuck on a project, you can look at their solution to see how they approached it.

You can see my version of the pricing plan with toggle.

Creating notification bar for emergencies and announcements

What is a notification bar?

A notification bar is a horizontal bar that appears at the top or bottom of your website. You can display emergency messages or announcements to your visitors. Messages about closings, updates, news or sales offers.

Create a Notification Bar for Website
Image by Gerd Altmann from Pixabay

How can you add a notification bar to your website?

It depends on how you want to do it. If you like to write code, you can make it yourself with HTML and CSS. If not, you can add a plugin or a third-party tool to your website.

1. Make your own

Are you using Bootstrap? Bootstrap has alerts. You can create your own bar with Bootstrap alerts. If you are using a different CSS framework, you can write your own.

See the Pen
Alert Animation (feat. Material Icons by Google)
by Ryan Young (@rcyou)
on CodePen.

2. Use a plugin to display message on your WordPress site

If you have a WordPress website, you may not want to edit your theme. Instead, you can add a plugin. WPBeginner explains how to use the plugins Optin Monster or Simple Notices for displaying important messages on your blog. If you are already using the plugin Advanced Custom Fields, you create custom emergency messages with it.

3. Use a third-party tool

You can choose to use a third-party tool like Getsitecontrol. They offer different ways of creating announcement bars for your website. You can add a sticky announcement bar or a slide-in banner that appears from the side.

Emergencies can occur at any time. You need to have a way of communicating with your customers and staff. Whether you make your own or use a tool, you can ensure that everyone can keep up to date on what is happening.