Performance: Why Rails API mode exists
MEDIUM IMPACT
This affects the initial page load speed and server response time by reducing unnecessary HTML rendering and asset loading.
class UsersController < ActionController::API def index users = User.all render json: users end end
class UsersController < ApplicationController def index @users = User.all render :index # renders full HTML view with layout end end
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full Rails with HTML views | N/A (server-side) | N/A | Larger payload delays browser paint | [X] Bad |
| Rails API mode with JSON only | N/A (server-side) | N/A | Smaller payload enables faster paint | [OK] Good |