I've written an ajax call to get some user specific content. But I found that the response of the ajax call is very slow. Indeed, I found that this is due to the slow response of the controller class. The controller class takes at least 2 seconds to give a empty json respnse while the controller is just a simple controller to handle the ajax call.
<?php
/**
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Vendor\ModuleName\Controller\Program;
class TestAjax extends \Magento\Framework\App\Action\Action {
public function __construct(
\Magento\Framework\App\Action\Context $context
) {
parent::__construct($context);
}
/**
* Forgot customer account information page
*
* @return \Magento\Framework\View\Result\Page
*/
public function execute() {
$testing= null;
$arr = array('testing' => $testing);
$jsonData = json_encode($arr);
$this->getResponse()->setHeader('Content-type', 'application/json');
$this->getResponse()->setBody($jsonData);
$this->getResponse()->sendResponse();
}
}