Performance: S3 cloud storage integration
This affects page load speed by how quickly assets are fetched from S3 and how the integration impacts server response times.
<?php // Use signed URLs with caching headers for direct client access use Illuminate\Support\Facades\Storage; Route::get('/image-url/{filename}', function ($filename) { $url = Storage::disk('s3')->temporaryUrl($filename, now()->addMinutes(10)); return response()->json(['url' => $url]); });
<?php // Directly fetching S3 files on every request without caching use Illuminate\Support\Facades\Storage; Route::get('/image/{filename}', function ($filename) { return Storage::disk('s3')->response($filename); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct server fetch from S3 | Minimal | 0 | Medium due to delayed resource arrival | [X] Bad |
| Signed URLs with client caching | Minimal | 0 | Low due to faster resource loading | [OK] Good |
Storage::disk('s3') to interact with these files, enabling safe online storage.Storage::disk('s3') to select the S3 disk, then put() to save files.put() method takes the filename first, then the file content.Storage::disk('s3')->put('docs/report.txt', 'Annual Report');
$exists = Storage::disk('s3')->exists('docs/report.txt');
return $exists ? 'File found' : 'File missing';put() method saves 'docs/report.txt' with content 'Annual Report'.exists() method checks if the file is present, which returns true after put().Storage::disk('s3')->delete('images/photo.png');delete() method needs only the filename; no second parameter is required.Storage::disk('s3')->put() with correct path and file content.Storage::disk('s3')->files('uploads') to get all files in that folder.Pass the test and this pattern moves unknown