I’m using a simple Ajax get method on local machine that providing to empty function in my server-side laravel code, and observe from browser network that response is returned randomly in from 250-500ms.
Can’t get any similar problem (if it’s a problem at all), isn’t it a lot response for nothing?
And if it normal, why response varies between two different values twice as much.
Also try it on different hostings and result sometimes worse.
$.get('/index/categories', { id: '1' }, function(data) {
});
(same with ajax)
Laravel:
public function getCategoriesJson()
{
}
2
Answers
If you use Laravels artisan serve as a dev server, you can only execute one script at a time. The second request will be queed until the first request is finished.
Laravel needs to boot on every request, meaning before any action is made Laravel has to start up, bootstrap its dependencies, create the application instance, create the routes and the router, and after all that it will resolve your request, so there are potential fixes for your problem.
php artisan route:cache
, but keep in mind that you have to flush this cache whenever you make changes to the routes