Tối Ưu Hiệu Suất WordPress: Sử Dụng Bộ Nhớ Cache
(https://i0.wp.com/make.wordpress.org/hosting/files/2018/08/full-page-caching-response-example.png)
1. Bộ Nhớ Cache Trình Duyệt
Bộ nhớ cache trình duyệt giúp tăng tốc độ tải trang và cải thiện trải nghiệm người dùng bằng cách lưu trữ các tệp tĩnh (như hình ảnh, CSS, JavaScript) trên trình duyệt. Để cấu hình bộ nhớ cache trình duyệt, bạn có thể chỉnh sửa tệp .htaccess:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
nginx
server {
location ~* \.(jpg|jpeg|gif|png|css|js|ico|svg)$ {
expires 1y;
add_header Cache-Control "public, no-transform";
}
}
2. Sử Dụng Plugin
Các plugin như "W3 Total Cache" hoặc "WP Super Cache" có thể dễ dàng cấu hình bộ nhớ cache thông qua giao diện quản trị WordPress. Đây là cách đơn giản và hiệu quả để quản lý bộ nhớ cache mà không cần chỉnh sửa mã thủ công.
3. Bộ Nhớ Cache Máy Chủ
Bộ nhớ cache máy chủ thường được sử dụng cho các trang web có lượng truy cập cao. Các giải pháp đơn giản nhất bắt đầu với việc lưu trữ bộ nhớ cache tại máy chủ cục bộ, trong khi các hệ thống phức tạp hơn có thể sử dụng nhiều máy chủ cache (reverse proxy servers) trước các máy chủ web chạy ứng dụng WordPress.
Opcode Cache: Thêm opcode cache như Opcache, hoặc WinCache trên IIS, sẽ cải thiện hiệu suất PHP nhiều lần.
Varnish Cache: Rất mạnh mẽ khi sử dụng với các plugin cache của WordPress như W3TC.
Bằng cách sử dụng đúng các phương pháp bộ nhớ cache trình duyệt, plugin và máy chủ, bạn có thể tối ưu hóa hiệu suất trang web WordPress của mình, mang lại trải nghiệm tốt hơn cho người dùng và giảm thiểu chi phí tài nguyên máy chủ.
Đọc Thêm
Core Caching Concepts in WordPress (https://developer.wordpress.org/advanced-administration/performance/cache/#browser-caching)
Best Practices for Speeding Up Your Web Site (https://developer.yahoo.com/performance/rules.html)
WebSiteOptimization.com: Use Server Cache Control to Improve Performance (https://www.websiteoptimization.com/speed/tweak/cache/)
https://github.com/varnishcache/varnish-cache
https://developer.wordpress.org/advanced-administration/performance/optimization/
https://make.wordpress.org/hosting/handbook/performance/
https://wedevs.com/blog/415761/wordpress-object-caching/
https://lehungio.com/framework/optimizing-wordpress-performance-using-caching/