InstantPWA on Ruby on Rails
Rails' application.html.erb layout wraps every view, so the InstantPWA snippet only needs to be added once inside <head>. Because Turbo Drive keeps the <head> element persistent across navigations rather than reloading it, the widget stays mounted and doesn't re-initialize on every link click.
Rails 6+ with or without Hotwire/Turbo. No importmap or asset-pipeline entry required.
How to set it up
- 1
Open app/views/layouts/application.html.erb
Find the <head> block, typically near yield(:head) or javascript_importmap_tags.
- 2
Paste the snippet before </head>
It's a plain script tag, so it doesn't need an importmap pin or Sprockets manifest entry.
- 3
Precompile assets if using Sprockets
bin/rails assets:precompile — this step isn't required for the InstantPWA tag itself, just your normal deploy.
- 4
Deploy and test
Turbo Drive won't reload <head> between page visits, so verify the popup on a fresh full-page load.
Common tasks on Ruby on Rails
FAQ
Does Turbo Drive break the install popup?+
No — Turbo preserves the <head> across visits, so InstantPWA initializes once per session rather than on every navigation.
Does it work with importmap-rails?+
Yes — the snippet is a standalone script tag and doesn't need to be pinned in config/importmap.rb.