Skip to content

Conversation

paulrobertlloyd
Copy link
Contributor

@paulrobertlloyd paulrobertlloyd commented Aug 30, 2025

We currently use Stimulus to find components in markup and initiate their respective JavaScript modules from NHS.UK frontend.

However, we’re using Stimulus to do a job NHS.UK frontend is already set up to do; it already finds components and initiates any required modules.

Where we may require Stimulus is for our own custom components for which, once you remove those we no longer use, we only have one: the accessible autocomplete component.

Turns out, NHS.UK frontend has an extendable API that lets us register additional components, so why not use that?

Removing unused controllers, and removing Stimulus, we can reduce the generated application bundle by ~20%.

We can also create a separate bundle for parent-facing pages (that doesn’t include Turbo, which doesn’t appear to be used on public pages) that is ~67% smaller!

Before (bytes) Remove unused controllers Remove Stimulus
application.js 239,731 228,826 177,587
public.js - - 66,979
application.js.gz 68,196 65,226 53,465
public.js.gz - - 23,343

This PR also does a few other bits of frontend tidy-up:

  • Removes test for service worker removed in Precompile fewer assets, remove service worker #4397
  • Adds a unit test for the autocomplete component (to check that it gets initiated)
  • Removes jest.setup.js and its unused mutationobserver-shim dependency
  • Imports styles for the action link component from nhsuk-frontend, and ensures we are using the updated markup introduced for this component in v10

@paulrobertlloyd paulrobertlloyd requested a review from a team as a code owner August 30, 2025 20:36
@paulrobertlloyd paulrobertlloyd added dependencies Pull requests that update a dependency file javascript Pull requests that update Javascript code css Pull requests that update CSS/SCSS code labels Aug 30, 2025
@paulrobertlloyd paulrobertlloyd force-pushed the reduce-javascript-bundle-size branch 2 times, most recently from 8888f18 to ceedff5 Compare August 31, 2025 00:47
@thomasleese thomasleese added this to the v3.4.0 milestone Sep 1, 2025
Import component styles from NHS.UK frontend, and use updated action link markup introduced in v10
@paulrobertlloyd paulrobertlloyd force-pushed the reduce-javascript-bundle-size branch from 1964769 to 4275d1a Compare September 1, 2025 08:23
@paulrobertlloyd paulrobertlloyd force-pushed the reduce-javascript-bundle-size branch from 4275d1a to edd762d Compare September 1, 2025 08:38
@paulrobertlloyd paulrobertlloyd force-pushed the reduce-javascript-bundle-size branch from edd762d to a558d30 Compare September 1, 2025 08:42
Copy link

sonarqubecloud bot commented Sep 1, 2025

@paulrobertlloyd paulrobertlloyd merged commit f32cd3b into next Sep 1, 2025
13 checks passed
@paulrobertlloyd paulrobertlloyd deleted the reduce-javascript-bundle-size branch September 1, 2025 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css Pull requests that update CSS/SCSS code dependencies Pull requests that update a dependency file javascript Pull requests that update Javascript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants