Skip to content

Commit

Permalink
Move Javascript modules to es6-components
Browse files Browse the repository at this point in the history
To prevent browsers evaluating JS that isn't supported, components that
contain code from govuk-frontend have been moved to a separate file
`es6-components.js` which is included in `application.html.erb` as a
script tag with `type="module"`.
  • Loading branch information
patrickpatrickpatrick authored and MartinJJones committed Jul 5, 2024
1 parent 60fc3f2 commit b358b54
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

//= link joint.css
//= link application.js
//= link es6-components.js
//= link dagre.js
//= link joint.layout.DirectedGraph.js
//= link joint.js
Expand Down
3 changes: 0 additions & 3 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//= require govuk_publishing_components/lib
//= require govuk_publishing_components/components/checkboxes
//= require govuk_publishing_components/components/error-summary
//= require govuk_publishing_components/components/govspeak
//= require govuk_publishing_components/components/intervention
//= require govuk_publishing_components/components/print-link
//= require govuk_publishing_components/components/radio
//= require govuk_publishing_components/components/step-by-step-nav
//= require govuk_publishing_components/components/table
12 changes: 12 additions & 0 deletions app/assets/javascripts/es6-components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// These modules from govuk_publishing_components
// depend on govuk-frontend modules. govuk-frontend
// now targets browsers that support `type="module"`.
//
// To gracefully prevent execution of these scripts
// on browsers that don't support ES6, this script
// should be included in a `type="module"` script tag
// which will ensure they are never loaded.

//= require govuk_publishing_components/components/checkboxes
//= require govuk_publishing_components/components/error-summary
//= require govuk_publishing_components/components/radio
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<%= csp_meta_tag %>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "test-dependencies" if Rails.env.test? %>
<%= javascript_include_tag "es6-components", type: "module" %>
<%= javascript_include_tag "application", defer: true %>
<%= yield :head %>
<% if content_item %>
Expand Down

0 comments on commit b358b54

Please sign in to comment.