Performance: Controller middleware
MEDIUM IMPACT
Controller middleware affects the server response time and can indirectly impact the time until the page starts rendering by adding processing before the controller action.
public function __construct() {
$this->middleware('auth'); // Use built-in lightweight middleware
// Move heavy logic inside controller or queue
}public function __construct() {
$this->middleware(function ($request, $next) {
// Heavy database queries or complex logic here
$data = DB::table('large_table')->get();
// Some complex processing
return $next($request);
});
}| Pattern | Server Processing | Response Delay | Impact on LCP | Verdict |
|---|---|---|---|---|
| Heavy logic in middleware | High CPU and DB queries | Adds 100+ ms delay | Worsens LCP significantly | [X] Bad |
| Lightweight middleware (e.g., auth) | Minimal CPU | Minimal delay | Improves LCP | [OK] Good |