Don't blame your users' browser

Restricting websites to modern browsers can cause headaches

When running rails new in a Rails 8 app, you’ll notice this innocuous and well-intentioned allow_browser line of code in the ApplicationController.

class ApplicationController < ActionController::Base
  # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
  allow_browser versions: :modern
end

One of the first things I do is delete it.

class ApplicationController < ActionController::Base
  # 💥 Delete "modern" browser support.
end

Why? For a lot of reasons.

Not everybody runs a modern browser

I view browser restrictions as “blaming the user”, which I think is an adversarial approach to building products for people. Not everybody has a “modern browser”. I’m not talking IE6 of antiquity, I’m talking people who might be stuck on an Intel MacBook that can’t upgrade their operating system, but have a perfectly good browser that is still highly capable.

webp is a great image format, but I’m perfectly happy serving up png and jpg images if it means more people can use my web application. Web Push is cool, but most web applications don’t need it. I haven’t run into problems with importmaps not working and since I use TailwindCSS, nested CSS isn’t a concern.

Breaks OpenGraph integrations

You know those social links that appear on links when you send them over text message or share on a social network? Those won’t work because the user agents of social media platforms don’t check out as a “modern browser”. Good luck tracking that down to the allowance of modern browser.

Sometimes restrictions are OK

I’m not categorically against browser restrictions, I just think it’s a bad default, especially for a framework as widely deployed as Rails. It’s important to consider the needs of all users, not just those with the latest and greatest browsers.

Do you want to learn Phlex 💪 and enjoy these code examples?

Support Beautiful Ruby by pre-ordering the Phlex on Rails video course.

Order the Phlex on Rails video course for $379 $289