Skip to content

Commit efb405f

Browse files
committed
Increment the env.version with asset_host and relative_url_root
This way such configurations will affect the asset fingerprints and the environment cache, since they might affect the assets contents.
1 parent f7576e0 commit efb405f

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/sprockets/railtie.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,16 @@ def configure(&block)
6666

6767
manifest_path = File.join(app.root, 'public', config.assets.prefix)
6868

69-
unless config.assets.version.blank?
70-
app.assets.version += "-#{config.assets.version}"
69+
# Configuration options that should invalidate
70+
# the Sprockets cache when changed.
71+
version_fragments = [
72+
config.assets.version,
73+
config.action_controller.relative_url_root,
74+
config.action_controller.asset_host
75+
].compact.join('-')
76+
77+
if version_fragments.present?
78+
app.assets.version += "-#{version_fragments}"
7179
end
7280

7381
# Copy config.assets.paths to Sprockets

test/test_railtie.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ def test_version
109109
assert_equal "test-v2", env.version
110110
end
111111

112+
def test_version_fragments
113+
app.configure do
114+
config.assets.version = 'v2'
115+
config.action_controller.asset_host = 'http://some-cdn.com'
116+
config.action_controller.relative_url_root = 'some-path'
117+
end
118+
app.initialize!
119+
120+
assert env = app.assets
121+
assert_equal "test-v2-some-path-http://some-cdn.com", env.version
122+
end
123+
112124
def test_configure
113125
app.configure do
114126
config.assets.configure do |env|

0 commit comments

Comments
 (0)