skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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.

    1. If you have a lot of packages, that could delay the boot, so remove any unused packages to decrease the load, because laravel loads all the packages on start using composer, and registers all their service providers to the app.
    2. Cache your routes, if your routes are not cached, then Laravel will have to generate them on every request, it’s a simple command php artisan route:cache, but keep in mind that you have to flush this cache whenever you make changes to the routes
    3. Use the debug bar to see what’s delaying your app, it provides very helpful data, you could find a problem with your queries which can delay the response, among other problems. install this package on development environment only
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search