Reduce JavaScript bundle size #4450
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!
This PR also does a few other bits of frontend tidy-up:
jest.setup.js
and its unusedmutationobserver-shim
dependencynhsuk-frontend
, and ensures we are using the updated markup introduced for this component in v10