Performance: Retrieving files
MEDIUM IMPACT
This affects page load speed and user experience by how quickly files like images or documents are served from the server to the browser.
<?php // Using Laravel's built-in file streaming response $filePath = storage_path('app/public/file.pdf'); return response()->file($filePath);
<?php // Directly reading file contents and returning response $filePath = storage_path('app/public/file.pdf'); $content = file_get_contents($filePath); return response($content, 200)->header('Content-Type', 'application/pdf');
| Pattern | Memory Usage | Response Time | Network Load | Verdict |
|---|---|---|---|---|
| Reading full file into memory | High | Slow start, blocks rendering | High | [X] Bad |
| Streaming file with response()->file() | Low | Fast start, non-blocking | Moderate | [OK] Good |
| No cache headers | Low | Fast start | High on repeat loads | [!] OK |
| Streaming with cache headers | Low | Fast start | Low on repeat loads | [OK] Good |