mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
PERF: Improve workbox loading strategy (#22019)
Previously workbox JS was vendored into our git repository, and would be loaded from the `public/javascripts` directory with a 1 day cache lifetime. The main aim of this commit is to add 'cachebuster' to the workbox URL so that the cache lifetime can be increased. - Remove vendored copies of workbox. - Use ember-cli/broccoli to collect workbox files from node_modules into assets/workbox-{digest} - Add assets to sprockets manifest so that they're collected from the ember-cli output directory (and uploaded to s3 when configured) Some of the sprockets-related changes in this commit are not ideal, but we hope to remove sprockets in the not-too-distant future.
This commit is contained in:
@ -16,6 +16,13 @@ module EmberCli
|
||||
assets +=
|
||||
Dir.glob("app/assets/javascripts/discourse/scripts/*.js").map { |f| File.basename(f) }
|
||||
|
||||
if workbox_dir_name
|
||||
assets +=
|
||||
Dir
|
||||
.glob("app/assets/javascripts/discourse/dist/assets/#{workbox_dir_name}/*")
|
||||
.map { |f| "#{workbox_dir_name}/#{File.basename(f)}" }
|
||||
end
|
||||
|
||||
Discourse
|
||||
.find_plugin_js_assets(include_disabled: true)
|
||||
.each do |file|
|
||||
@ -62,4 +69,13 @@ module EmberCli
|
||||
JSON.parse(ember_source_package_raw)["version"]
|
||||
end
|
||||
end
|
||||
|
||||
def self.workbox_dir_name
|
||||
return @workbox_base_dir if defined?(@workbox_base_dir)
|
||||
|
||||
@workbox_base_dir =
|
||||
if (full_path = Dir.glob("app/assets/javascripts/discourse/dist/assets/workbox-*")[0])
|
||||
File.basename(full_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user