FIX: update cache times for service workers

Add a last modified time.

Register newer service workers and claim clients more quickly.
This commit is contained in:
Jeff Wong
2018-05-14 12:29:24 -07:00
parent b004503c62
commit e4a33cbc0a
2 changed files with 8 additions and 1 deletions
+4 -1
View File
@@ -160,8 +160,11 @@ class StaticController < ApplicationController
format.js do
# https://github.com/w3c/ServiceWorker/blob/master/explainer.md#updating-a-service-worker
# Maximum cache that the service worker will respect is 24 hours.
immutable_for 24.hours
# However, ensure that these may be cached and served for longer on servers.
immutable_for 1.year
path = File.expand_path(Rails.root + "public/assets/#{Rails.application.assets_manifest.assets['service-worker.js']}")
response.headers["Last-Modified"] = File.ctime(path).httpdate
render(
plain: Rails.application.assets_manifest.find_sources('service-worker.js').first,
content_type: 'application/javascript'