Why pagination and all other AJAX requests are slow on my PrestaShop site? That's probably due to Gzip for "application/json" is not enabled on your site. Gzip is crucial for page loading speed, it's enable on most modern hostings, but gzip for "application/json" is not always enabled. If it's not enabled, then all ajax request would be slow, because ajax responses are in "application/json". Enabling it can speed ajax requests up for 10+ times.
What can be sped up after applying this solution.
Pagination.
Switching combination.
Add-to-cart.
Quick view.
Easycheckout module.
Product comment module.
Product search module.
And all other features which use AJAX.
How to check if Gzip for "application/json" is enabled or not?
Use Chrome to open a category page which has pagination.
Open chrome's developer tools, switch to "Network" tab > "XHR" sub tab.
Click page 2.
A new row will show on the XHR tab, click on it, check if you can find "content-encoding: gzip" the "Response headers" section. The image blow shows gizp for "application/json" is enabled.
The image blow shows gizp for "application/json" is not enabled.
How to enable gizp for "application/json"
Put this code to the very bottom of your .htaccess file which is in the root folder of your site. This modification works for all PrestaShop 1.6 and PrestaShop 1.7 sites, no matter which theme you are using.
EDIT!!! Sorry, I did not have the code placed in the htaccess file. I had all the code for GZIP to work, EXCEPT the "DEFLATE application/json". I added and now I had GZIP for product combinations too, faster now!!
THANKS FOR THE POST!
____________________________________
Hi Jonny! That's a great post, thank you.
A question: I did the test on my shop and I'm getting the "content-encoding: gzip" with pagination, but no with changing product combinations. Is that ok?
Code for pagination:
cache-control: no-store, no-cache, must-revalidate
content-encoding: gzip
content-length: 46867
content-type: text/html; charset=utf-8
date: Tue, 05 Mar 2019 09:01:18 GMT
expires: Thu, 19 Nov 1981 08:52:00 GMT
p3p: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"
powered-by: PrestaShop
pragma: no-cache
server: nginx
Hey,
Thanks for the post. Could it not work because of cloudflare caching?
https://gyazo.com/7381234821121ceacc07bd4124a8bb9e
Prestashop 1.7.5.1
Hola, he ingresado el codigo en .htaccess y obtengo el error 500 del servidor al ingresar a cualquier menu en el backoffice
Como puedo solucioonarlo
great tutorial it worked for me x3 items faster
i made a account here just to say thank you
Maybe you didn't enter the correct code.
Is it actual for Apache only? What about nginx?
If you are using nginx, please see the documentation: https://docs.nginx.com/nginx/admin-guide/web-server/compression/
Hi jonny thanks for the tip,
What I am getting though is
content-type: application/octet-stream
Using ps 1.6. and transformer 3.x
Did you do the modification to the .htaccess file?
No, No I was trying to see if this appliable to our site
The tutorial works for all sites which are runing prestashop 1.6 and prestashop 1.7
Is it active https://ibb.co/6nbRvPK?
The webservice say that I only have to active Apache optimization in PS ¿?
Thanks
What we are looking for is the gzip in the "Response headers" section, not the gzip in the "Request header" section.
In my htaccess I have:
AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/x-javascript font/ttf application/x-font-ttf font/otf application/x-font-otf font/opentype image/svg+xml
is it a server problem or I'm checking a page that are not using AJAX request?
Best regards.
You need to add a piece of code to the htaccess file, check the 'How to enable gizp for “application/json”" section above.
Excellent, Thank you Jonny!
EDIT!!! Sorry, I did not have the code placed in the htaccess file. I had all the code for GZIP to work, EXCEPT the "DEFLATE application/json". I added and now I had GZIP for product combinations too, faster now!!
THANKS FOR THE POST!
____________________________________
Hi Jonny! That's a great post, thank you.
A question: I did the test on my shop and I'm getting the "content-encoding: gzip" with pagination, but no with changing product combinations. Is that ok?
Code for pagination:
cache-control: no-store, no-cache, must-revalidate
content-encoding: gzip
content-length: 46867
content-type: text/html; charset=utf-8
date: Tue, 05 Mar 2019 09:01:18 GMT
expires: Thu, 19 Nov 1981 08:52:00 GMT
p3p: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"
powered-by: PrestaShop
pragma: no-cache
server: nginx
Code for changing combinations:
cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
content-type: application/json
date: Tue, 05 Mar 2019 09:03:08 GMT
server: nginx
status: 200
vary: User-Agent
x-powered-by: PHP/7.2.15
x-powered-by: PleskLin
Thanks!
Yes, all ajax actions will be faster, like add to cart, search auto suggestion, etc. So spread the post out.