Browser compatibility is critical for ensuring that a website displays and performs properly across several web browsers. Every browser renders code differently, thus compatibility testing is critical for reaching a larger audience. It involves evaluating how a website appears in several browsers such as Chrome, Firefox, Safari, and Internet Explorer.
As the number of mobile users grows, interoperability with mobile platforms becomes increasingly important.
Before
Before Rails 7.2, browser compatibility was detected using the browser gem
To detect whether a browser can be considered as modern or not, we create a method that abstracts our versioning constraints.
After
Rails 7.2 will introduce allow_browser to help us specify the minimum browser versions required for the application
We can set the allow_browser to our ApplicationController as below to restrict support to browsers that natively support webp images, web push, badges, import maps, CSS nesting + :has
We can also customize the allow_browser method to specify browser versions as in the example below
In the above method, allow_browser will allow all versions of Chrome and Opera and only Safari above 16.4+ and Firefox 121+ but no versions of “Internet Explorer” (ie) is allowed
If the application does not support Safari, then we can disable it by setting safari as false
A browser that is blocked will by default be served the file in public/426.html with a HTTP status code of 426 Upgrade Required.