Only import the js from GOV.UK Frontend that the website is using #3766
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.
Change
Updates
application.js
to only initialise the components that the website is using to optimise website performance. Part of #3732.Notes
This change reduces
application.js
by approximately 36kb.This change imports the component js directly from the mjs in the component folders instead of importing directly from
govuk-frontend
via combined curly brackets as we'd expect our users to do. This is because we've noticed as part of this work that our tree shaking doesn't work when importing the "expected" way and only works when importing the components directly. See alphagov/govuk-frontend#4957.This was made possible by Romaric's work to figure out what
data-module
's the website is using in #3760.There are a couple of components that we're using that have js associated with them that I haven't included in the import:
Header
The header js is only used to manage the mobile menu view toggle. We're using custom navigation that doesn't rely on or interact with this js so importing it is unnecessary. I've additionally removed
data-module="govuk-header"
as this isn't being used by anything.Radios
We're using radios on the cookie banner page but the radios js is only used to manage conditional reveals, which we aren't using.