alphagov / govuk-design-system

One place for service teams to find styles, components and patterns for designing government services.
https://www.gov.uk/design-system
MIT License
512 stars 232 forks source link

Avoid unnecessary 301 redirects between pages in the Design System #1908

Closed 36degrees closed 3 years ago

36degrees commented 3 years ago

What

Many of the links to other pages in the Design System omit the trailing slash.

When you omit the trailing slash from a URL in the Design System, the web server will redirect you to the version with the trailing slash – for example if you try to go to design-system.service.gov.uk/components you'll be redirected to design-system.service.gov.uk/components/.

This adds an extra round trip to the server which could otherwise be avoided if we ensure that all links include the trailing slash.

The broken link checker is currently configured to explicitly allow these redirects:

https://github.com/alphagov/govuk-design-system/blob/67ba57d6ae3816bdf57bcf273ad51ad2c6db57f8/lib/metalsmith.js#L287-L290

Disabling this would cause the link checker to flag links that redirect, causing builds to fail.

This would potentially mean more failing builds (and thus more back and forth before merging) whilst team members get in the habit of including the trailing slash, so we need to decide if that overhead is worth it for the performance gains.

Why

Avoiding the unnecessary redirect will improve performance, especially for users on slower connections.

For example, on a simulated slow 3G connection, the extra round trip for the 301 redirect takes approx 2 seconds, out of a total 5.77s (till DOMContentLoaded).

Screenshot 2021-09-28 at 15 18 52

The performance impact is still relatively worthwhile but is objectively less noticeable for users on a fast connection – on a 120mb fibre connection the request takes 60ms out of a total 300ms (till DOMContentLoaded).

Who needs to know about this

Developers, anyone that regularly edits the content on the Design System

Done when

36degrees commented 3 years ago

Given I (thought I…) had done most of the work, I've finished up the changes to get the tests passing and opened a PR… now we just have to decide if we actually want to do this or not!