Skip to content

Commit

Permalink
Merge pull request #5082 from dodona-edu/fix/production-caching
Browse files Browse the repository at this point in the history
Fix assets not available in production
  • Loading branch information
jorg-vr authored Oct 26, 2023
2 parents ca58efc + 2090dca commit 9d856a4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
9 changes: 9 additions & 0 deletions config/deploy/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@
end
end
end
before :publishing, :asset_stuff do
on roles :web do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, 'assets:nodigest'
end
end
end
end
end
3 changes: 3 additions & 0 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
# Compress JavaScripts and CSS.
config.assets.js_compressor = :terser

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false

# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
Expand Down
5 changes: 4 additions & 1 deletion config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )

Rails.application.config.assets.nodigest = []
# These files are fetched from within other js assets
# so they do not support rails sprockets renaming them
# We need to provide them as assets without digest
Rails.application.config.assets.nodigest = ['*.nodigest.js', '*.load_by_url']
2 changes: 1 addition & 1 deletion config/webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const config = {
filename: "[name].js",
sourceMapFilename: "[name].js.map",
path: path.resolve(__dirname, "..", "..", "app/assets/builds"),
chunkFilename: "[name].[chunkhash].js",
chunkFilename: "[name].[chunkhash].nodigest.js",
},
resolve: {
modules: ["node_modules", "app/assets/javascripts"],
Expand Down
8 changes: 5 additions & 3 deletions lib/tasks/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ namespace :assets do
task nodigest: :environment do
assets_path = File.join(Rails.root, 'public', Rails.configuration.assets.prefix)
Rails.configuration.assets.nodigest.each do |asset|
source = File.join('app/assets/javascripts', asset)
dest = File.join(assets_path, asset)
FileUtils.copy_file(source, dest)
Dir.glob(File.join('app/assets/builds', asset)).each do |source_path|
file_name = File.basename(source_path)
dest_path = File.join(assets_path, file_name)
FileUtils.copy_file(source_path, dest_path)
end
end
end
end

0 comments on commit 9d856a4

Please sign in to comment.