mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 08:49:03 +08:00
FEATURE: Normalize the service worker route (#8359)
* FEATURE: Normalize the service worker route Update cache headers so they are not immutable outside of the rails app Add the ability to purge the service worker cache from localhost Rails -> nginx will pass immutable flags so the file is cached until reloaded. In most cases, nginx will have its cache flushed on rebuild (new image) For those needing dynamic re-caching (such as upgrading via the UI), a rake task for flushing the service worker script is provided through `assets:flush_sw`
This commit is contained in:
@ -68,6 +68,19 @@ task 'assets:precompile:css' => 'environment' do
|
||||
end
|
||||
end
|
||||
|
||||
task 'assets:flush_sw' => 'environment' do
|
||||
begin
|
||||
hostname = Discourse.current_hostname
|
||||
default_port = SiteSetting.force_https? ? 443 : 80
|
||||
port = SiteSetting.port.to_i > 0 ? SiteSetting.port : default_port
|
||||
STDERR.puts "Flushing service worker script"
|
||||
`curl -s -m 1 --resolve '#{hostname}:#{port}:127.0.0.1' #{Discourse.base_url}/service-worker.js > /dev/null`
|
||||
STDERR.puts "done"
|
||||
rescue
|
||||
STDERR.puts "Warning: unable to flush service worker script"
|
||||
end
|
||||
end
|
||||
|
||||
def assets_path
|
||||
"#{Rails.root}/public/assets"
|
||||
end
|
||||
|
Reference in New Issue
Block a user