Web Development

Dr Derek Bridge
School of Computer Science & Information Technology
University College Cork

Lecture Objectives

  • learn what slows your web site down
  • learn some simple techniques for improving performance

Objectives

are usable by all users;
are usable on all devices;
are usable in all browsers;
rank highly in search engine results;
load quickly;
are maintainable.

Web Page Performance

Web pages are getting bigger.

Connection speeds are not increasing so quickly.

Hence, the web is getting slower.

Measuring Performance

Measure and analyse!

E.g. the Network tab on Chrome's Developer Tools.

E.g. the Lighthouse tab on Chrome's Developer Tools.

General Advice

Things web & network administrators can do to help us:

  • Configure servers to make as much use of caching as possible;
  • Distribute load over multiple servers;

General Advice

Things web developers can do:

  • Reduce the number of requests;
  • Decrease the size of each resource;
  • Consider conditional loading or lazy loading;

Reduce the Number of Requests

E.g.:

Do you really need all those images? fonts? videos? audio files?

Eliminate some!

Reduce the Number of Requests

E.g.:

Use image sprites (background, foreground).

By merging resources, this reduces requests.

Decrease the Size of Each Resource

E.g.:

Minify your HTML, CSS and JavaScript.

Compress your HTML, CSS and JavaScript.

Conditional Loading and Lazy Loading

Conditional loading:
Only fetch resources that the client needs.

Lazy loading:
Delay fetching non-essential resources until the essential parts of a page are on-screen.

Images

Since images are a major cause of performance problems, we look at them further in more detail.

Two Major Types of Images

There are bitmapped images (aka raster images).
Bitmapped image formats include
GIF, JPEG, PNG, and WebP (also AVIF and JPEG XL).

There are also vector images.
The most popular vector format is
Scalable Vector Graphics (SVG).

Bitmapped Images

  • Consist of pixels (coloured dots) in a grid.
  • Their quality depends on their resolution: the number of pixels per inch.
  • When software decreases the size of such images, it throws pixels away.
  • When software increases the size of such images, it inserts new pixels and must guess their colour.

Bitmapped Images

There are two kinds of bitmapped images.

direct colour indexed colour
e.g. JPEG e.g. GIF

Some image formats support both, e.g. PNG, WebP.

Direct Colour Images

The image file specifies the colour of each pixel by giving, e.g., an RGB code.

Good for images with continuous changing shades and soft transitions, e.g. photos.

Indexed Colour Images

The image file contains a palette of colours.
It then specifies the colour of each pixel by giving the colour's position on the palette.

E.g. GIF — uses a palette of up to 256 colours.

Good for images with large areas of solid, flat colour, e.g. logos, icons, charts, cartoons.

Vector Images

Vector images are defined using code, which describes lines, rectangles, circles, etc.
E.g. SVG:

You can include SVG images in separate files or directly in your HTML.

SVG

Advantages:
scalable without loss of quality
smaller than bitmapped images
text remains accessible
can be styled by CSS or targetted by JavaScript.

Disadvantage:
for anything other tham simple diagrams, they require a lot of code.

Quick Comparison

compression transparency animation
JPEG lossy no no
GIF lossless no yes
PNG lossless yes no
WebP both yes yes
SVG lossless yes yes

Decreasing the Size of Images

  • Choose a format that results in smaller files:
    • E.g. SVG rather than bitmapped (often).
    • E.g. PNG rather than GIF (often).
    • E.g. WebP or PNG rather than JPEG .
    • E.g. AVIF or JPEG XL when available.
  • For formats such as JPEG, PNG, WebP, AVIF and JPEG XL, increase the compression level as much as you can and reduce the resolution if you can.

G'luck!