PrestaShop Performance Optimization
PrestaShop 8.x on standard configuration gives TTFB 1.5–4 seconds on catalog with 2000+ products. Reasons: Smarty template compilation without cache, ORM with excessive JOIN queries, built-in file-based cache. Optimization gives TTFB 200–500ms with correct stack.
PrestaShop Built-in Cache
Admin > Advanced Parameters > Performance — main optimization panel.
Smarty:
- Template compilation: Never recompile template files (not on dev)
- Cache: Yes
- Multi-front optimizations: Yes
- Clear cache: Never clear cache files
CCC (Combine, Compress, Cache):
- Smart cache for stylesheets: Yes
- Smart cache for JavaScript: Yes
- Apache optimization: Yes (generates
.htaccessrules) - Minify HTML: Yes
Media servers — specify CDN domain for static files if used.
Memcache/Redis as Cache Backend
By default PrestaShop caches to files. Switch to Memcache or Redis through Admin > Advanced Parameters > Performance > Caching:
- Caching system: Memcache or Redis
- Add server:
127.0.0.1:6379
For Redis additionally in config/config.inc.php (if version doesn't support Redis via UI):
define('_PS_CACHE_ENABLED_', '1');
define('_PS_CACHING_SYSTEM_', 'CacheRedis');
CacheRedis class in PrestaShop 8 works via Predis. If using phpredis extension — 15–20% faster.
PHP OPcache
opcache.enable=1
opcache.memory_consumption=256
opcache.max_accelerated_files=20000
opcache.validate_timestamps=0 ; production
opcache.revalidate_freq=0
opcache.interned_strings_buffer=32
opcache.fast_shutdown=1
PrestaShop has large codebase — max_accelerated_files=20000 is necessary, standard 10000 is not enough.
MySQL: Indexes and Slow Log
-- Common PrestaShop queries without optimal index
ALTER TABLE ps_product_lang
ADD INDEX idx_id_lang (id_lang, id_product);
ALTER TABLE ps_category_product
ADD INDEX idx_id_category_pos (id_category, position);
ALTER TABLE ps_search_word
ADD INDEX idx_word (word(50));
Slow query log:
[mysqld]
slow_query_log = 1
slow_query_log_file = /var/log/mysql/prestashop-slow.log
long_query_time = 1
log_queries_not_using_indexes = 1
Typical culprit in slow log — getProducts() query sorted by sales without index on ps_product_sale.
Modules and Their Performance Impact
Each active PrestaShop module adds hooks to page lifecycle. Diagnostics:
// config/defines.inc.php (temporarily)
define('_PS_DEBUG_PROFILING_', true);
After enabling, Debugger bar appears at bottom of page in browser with execution time for each hook.
Problematic module categories:
- SEO modules — often make 3–10 additional requests per page
- Live chat modules — load external scripts synchronously
- Review modules — COUNT queries without cache for each product in listing
Nginx Configuration
# Static files
location ~* \.(jpg|jpeg|png|webp|gif|ico|svg|woff2|css|js)$ {
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
try_files $uri =404;
}
# Gzip
gzip on;
gzip_types text/plain text/css application/json application/javascript image/svg+xml;
gzip_comp_level 5;
gzip_min_length 512;
gzip_vary on;
# Forbid direct access to PrestaShop classes
location ~* \.(log|tpl|twig|sass|yml|lock)$ {
deny all;
}
WebP and Images
PrestaShop 1.7.7+ supports WebP via Admin > Design > Image settings. Enable WebP formats — image sizes reduced by 25–40%. On listing page with 24 products, saves 500–800 KB.
Additionally — regenerate thumbnails with new sizes:
php bin/console prestashop:generate:thumbnails --type=all
Work Timeline
Setup built-in cache, OPcache, PHP-FPM, Redis, nginx: 1–2 days. Module audit and disabling slow ones: 1 day. Enable WebP, regenerate thumbnails, MySQL indexes: 0.5–1 day.







