I save some photos privately in the storage and show them to the user when needed using the following method.
in route :
Route::get('/serveFile/{address?}', [FileController::class, 'serveFile'])
->where('address', '.*')->name('serveFile');
in controller :
public function serveFile($address = null)
{
return response()->file(storage_path($address));
}
finally, the src of the photo or file or … is placed in the html as follows:
https://DOMAIN/serveFile/app/DIRECTORYNAME/2024/06/15/DIRECTORYNAME/NAME.jpg
Everything is good and there is no problem in loading and working logic. Only when I want to show a large number of images, the browser puts them in a queue and makes them pending and loads the images two by two.
look at this picture :
Images with lazy load and without it, both modes have problems.
What is wrong?
i tried changing controller code and increasing CPU count and change hosting. nothing changed.
i need some advise 🙂
2
Answers
Follow below steps to fresh start laravel project
step 1 : composer create-project –prefer-dist laravel/laravel project-name
step 2 : cd project-name
step 3 : cp .env.example .env
step 4 : php artisan key:generate
step 5 : update details of database connection at .env file
step 6 : php artisan migrate
step 7 : php artisan serve
What HTTP version are you using? This seems like a HTTP limitation.
HTTP/2 allows better use of the network by allowing multiple downloads in near parallel through multiplexing.
Similar issue Huge amount of images – HTTP/1.1 vs HTTP/2?.