Does anyone else have a Rails controller to dynamically generate a service worker? Am I a monster?
@james def serviceworker
current_site = CamaleonCms::Site.first.decorate
manifest = JSON.parse File.read(Rails.root.join 'public', 'packs', 'manifest.json')
pack_urls = manifest.keys.filter_map do |pack_name|
asset_pack_url(pack_name) if pack_name.match? /\.(css|js|woff2)\z/
@cache_version = Digest::MD5.hexdigest manifest.to_s
@cache_keys = [*pack_urls, *PERMANENT_URLS]
@cache_keys += [current_site.the_logo, current_site.the_icon]
@james This lets me include content specified in our CMS as well as webpacker assets and non-fingerprinted/third-party assets. The method is the only one in my ServiceWorkerController.
A Mastodon instance for Rubyists & friends