Skip to content

Commit bb752f7

Browse files
Only render JS tags for pages with JS
1 parent 924aa56 commit bb752f7

File tree

15 files changed

+38
-36
lines changed

15 files changed

+38
-36
lines changed

app/assets/config/manifest.js

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
// /admin site
55
//= link admin.css
6-
//= link bootstrap.min.js
76

87
// Mini sites
98
//= link to_change_everything.css

app/javascript/admin.js

-4
This file was deleted.

app/views/2017/articles/show.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<% end %>
88

99
<% if live_blog_article? && @article.updated_at.after?(1.week.ago) %>
10-
<% content_for :head do %>
11-
<%= javascript_import_module_tag "live_blog" %>
10+
<% content_for :javascript do %>
11+
<%= javascript_import_module_tag :live_blog %>
1212
<% end %>
1313

1414
<%= render_themed "articles/live_blog", article_slug: @article.slug %>

app/views/2017/shared/head/_link_tags.html.erb

-2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,3 @@
2424
<!-- Browser hints -->
2525
<link rel="dns-prefetch" href="https://assets.crimethinc.com">
2626
<link rel="dns-prefetch" href="https://cdn.crimethinc.com">
27-
28-
<%= yield :head %>

app/views/2017/support/edit.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@
6868
<%= t('views.support.edit.expires_at', minutes: minutes_until_expiration(@support_session)) %>
6969
</p>
7070

71-
<% content_for :head do %>
72-
<%= javascript_import_module_tag "support" %>
71+
<% content_for :javascript do %>
72+
<%= javascript_import_module_tag :support %>
7373
<% end %>

app/views/2017/support/new.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,6 @@
9595
});
9696
</script>
9797

98-
<% content_for :foot do %>
99-
<%= javascript_import_module_tag "support" %>
98+
<% content_for :javascript do %>
99+
<%= javascript_import_module_tag :support %>
100100
<% end %>

app/views/layouts/2017/_application.html.erb

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
prefix: html_prefix do %>
77
<head>
88
<%= render_themed "shared/head" %>
9-
<%= javascript_importmap_tags %>
9+
1010
<%= yield :head %>
11+
12+
<% if content_for(:javascript).present? %>
13+
<%= javascript_importmap_tags %>
14+
<%= yield :javascript %>
15+
<% end %>
1116
</head>
1217

1318
<body id="<%= body_id %>">
@@ -29,7 +34,5 @@
2934
</main>
3035

3136
<%= render_themed "shared/footer" %>
32-
33-
<%= yield :foot %>
3437
</body>
3538
<% end %>

app/views/layouts/2025/_application.html.erb

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414

1515
<%# TODO: add favicon link tags here %>
1616

17-
<%= javascript_importmap_tags %>
1817
<%= render 'layouts/2025/auto_dark_mode' %>
1918
<%= render 'layouts/2025/stylesheets' %>
19+
20+
<% if content_for(:javascript).present? %>
21+
<%= javascript_importmap_tags %>
22+
<%= yield :javascript %>
23+
<% end %>
2024
</head>
2125

2226
<body>

app/views/layouts/admin.html.erb

+10-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@
3131
<link rel="manifest" href="/manifest.json">
3232

3333
<%= stylesheet_link_tag "admin", media: "all" %>
34-
<%= javascript_importmap_tags %>
35-
<%= javascript_import_module_tag "bootstrap" %>
36-
<%= yield(:head) %>
3734

38-
<%= render 'layouts/2025/auto_dark_mode' %>
35+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-0pUGZvbkm6XF6gxjEnlmuGrJXVbNuzT9qBBavbLwCsOGabYfZo0T0to5eqruptLy" crossorigin="anonymous"></script>
36+
37+
<%= yield :head %>
38+
39+
<% if content_for(:javascript).present? %>
40+
<%= javascript_importmap_tags %>
41+
<%= yield :javascript %>
42+
<% end %>
43+
44+
<%= render 'layouts/2025/auto_dark_mode' %>
3945
</head>
4046

4147
<body id="<%= body_id %>">

app/views/layouts/steal_something_from_work_day.html.erb

+7-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@
1414
<%= render 'steal_something_from_work_day/head/fav_and_touch_icons' %>
1515

1616
<%= stylesheet_link_tag 'steal-something-from-work-day', media: 'all' %>
17-
<%= javascript_importmap_tags %>
18-
<%= yield(:head) %>
17+
18+
<%= yield :head %>
19+
20+
<% if content_for(:javascript).present? %>
21+
<%= javascript_importmap_tags %>
22+
<%= yield :javascript %>
23+
<% end %>
1924
</head>
2025

2126
<body id='<%= body_id %>' data-bs-spy='scroll' data-bs-target='#section-list' data-bs-offset='0'>

app/views/shared/head/_link_tags.html.erb

-2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,3 @@
2424
<!-- Browser hints -->
2525
<link rel="dns-prefetch" href="https://assets.crimethinc.com">
2626
<link rel="dns-prefetch" href="https://cdn.crimethinc.com">
27-
28-
<%= yield :head %>

app/views/steal_something_from_work_day/head/_link_tags.html.erb

-2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,3 @@
2424
<!-- Browser hints -->
2525
<link rel="dns-prefetch" href="https://assets.crimethinc.com">
2626
<link rel="dns-prefetch" href="https://cdn.crimethinc.com">
27-
28-
<%= yield :head %>

app/views/steal_something_from_work_day/show.html.erb

-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,3 @@
2929
<br><br><br><br><br>
3030
</main>
3131
</div><!-- .main-wrapper -->
32-
33-
<% content_for :head do %>
34-
<%= javascript_import_module_tag "bootstrap" %>
35-
<% end %>

config/importmap.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# Pin npm packages by running ./bin/importmap
22

3-
pin 'application', preload: false
3+
pin :application
44

55
# Our JS files
6-
pin 'support', preload: false
7-
pin 'bootstrap', preload: false, to: 'bootstrap.min.js'
6+
pin :support
87

9-
# Hotwired JS https://hotwired.dev
8+
# Stimulus JS (part of Hotwire JS) https://stimulus.hotwired.dev
109
pin '@hotwired/stimulus', to: 'stimulus.min.js', preload: false
1110
pin '@hotwired/stimulus-loading', to: 'stimulus-loading.js', preload: false
1211

config/initializers/assets.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
# Precompile additional assets.
1111
# application.js, application.css, and all non-JS/CSS in the app/assets
1212
# folder are already added.
13-
# Rails.application.config.assets.precompile += %w[bootstrap.min.js admin.css]
13+
# Rails.application.config.assets.precompile += %w[]

0 commit comments

Comments
 (0)