Tối ưu tốc độ load cho website sử dụng wordpress giúp bạn vượt qua đối thủ trong google Search và tạo sự dễ chịu cho khách hàng truy cập vào website. Các công cụ kiểm tra tốc độ 1. http://developers.google.com/speed/pagespeed/insights/ 2. http://tools.pingdom.com/fpt/ 3. http://gtmetrix.com/ Nén kích thước cái file trong mã nguồn Làm bằng tay 1. Nén các file CSS http://www.csscompressor.com/ Ví dụ style.css của các bạn có dạng: Mã: #container { background: #fff; float: left; padding: 20px 0 30px 0; width: 100%; z-index: 100; } Sau khi nén nó có dạng Mã: #container{background:#fff;float:left;width:100%;z-index:100;padding:20px 0 30px} Giúp loại bỏ khoản trắng, xuống dòng và các kí tự thừa. giảm được tầm 30-50% size của file css đó các bạn. 2. 2. Nén file Java Scipt JS. http://compressorrater.thruhere.net/ cũng giống như css ở trên giúp loại bỏ ký tự thừa và các định nghĩa giống nhau trong JS. 3. Nén HTML và PHP Cái này không quan trọng như sẵn viết thì giới thiệu luôn. đồ chơi: http://htmlcompressor.com/compressor/ Sử dụng Plugin: Dùng Plugin WP Minify. (Khi sử dụng Minify, các bạn không nén theo các cách trên nữa) http://wordpress.org/plugins/wp-minify/ Đó là cách làm bằng tay mà mình hay dùng còn nếu dùng Plugin thì bạn cài thêm thằng WP Minify là nó có thể đảm nhiệm hết các vai trò ở trên. Tối ưu hóa dung lượng hình ảnh Sử dụng plugin WP Smush.it Download: http://wordpress.org/plugins/wp-smushit/ Sử dụng website Online: http://compressnow.com/ Đối với các hình ảnh thô chưa được tối ưu có thể giảm đến 70-80%. Click vào Multiple Images để tối ưu nhiều file cùng 1 lúc. Sử dụng nén Gzip Thêm đoạn code sau vào file .htaccess Mã: <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE image/x-icon AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE text/x-js AddOutputFilterByType DEFLATE image/svg+xml AddOutputFilterByType DEFLATE application/x-font-ttf AddOutputFilterByType DEFLATE application/x-font AddOutputFilterByType DEFLATE font/opentype AddOutputFilterByType DEFLATE font/otf AddOutputFilterByType DEFLATE font/ttf AddOutputFilterByType DEFLATE application/x-font-truetype AddOutputFilterByType DEFLATE application/x-font-opentype AddOutputFilterByType DEFLATE application/vnd.ms-fontobject AddOutputFilterByType DEFLATE application/vnd.oasis.opendocument.formula-template </IfModule> Sử dụng bộ nhớ đệm Cache Bước 1: Mở file wp-config.php chèn đoạn này: define( ‘WP_CACHE’, true ); Dưới đoạn này /* That’s all, stop editing! Happy blogging. */ Sau đó lưu lại. Bước 2: CHMOD file .htaccess (làm trước khi cài plugin và chỉ dành cho máy chủ Apache) thành 775. Bước 3. Tải plugin và kích hoạt như bình thường. Sau đó vào Settings -> Permalinks thiết lập đường dẫn tĩnh nếu bạn chưa thiết lập. Bước 4. Cấu hình WP Super Cache Vào Settings -> WP Super Cache, chọn tab Easy và chọn Caching On. Sau đó mở qua tab Advanced và chọn vào một số tùy chọn mà mình ghi dưới đây. Cache hits to this website for quick access. (Recommended) Use mod_rewrite to serve cache files. (Recommended) – Chuyển đổi phương thức cache thông thường sang rewrite cache, tức là ghi cache vào ổ cứng. Don’t cache pages for known users. (Recommended) – Không cache với các thành viên đăng nhập (kể cả Admin), mục đích là dễ cho bạn chỉnh sửa giao diện mà không cần tắt cache. Don’t cache pages with GET parameters. (?x=y at the end of a url) – Nên chọn vì nếu không nó sẽ cache luôn trang kết quả tìm kiếm. Clear all cache files when a post or page is published or updated. – Xóa cache khi có post hoặc page được đăng mới hay cập nhật lại. Only refresh current page when comments made. – Xây dựng lại cache trong bài khi có bình luận mới được đăng lên. Sau đó bạn ấn vào nút Update Status ở dưới. Bây giờ nó sẽ kêu bạn cập nhật file .htaccess Nhưng do chúng ta đã CHMOD từ trước nên không cần update thủ công nữa mà cho nó tự sửa luôn. Kéo xuống dưới một chút và ấn vào nút Update Mod_Rewrite Rule, nếu nó chuyển thành màu xanh lá cây là oke. Sau đó, bạn kéo xuống tí nữa để đến phần Expiry Time & Garbage Collection, bạn chọn là Timer và đặt số giây là 7200 Cuối cùng là kéo xuống tí nữa và ấn nút Change Expiration. Bây giờ bạn quay lại tab Easy và ấn nút Test Cache, nếu nó hiển thị 3 dòng có chữ OK màu xanh lá cây là oke. Thêm đoạn code này vào file .htaccess để tăng thời gian lưu các file cache Mã: # Enable expiration control ExpiresActive On # Default expiration: 1 hour after request ExpiresDefault "now plus 1 hour" # CSS and JS expiration: 1 week after request ExpiresByType text/css "now plus 1 week" ExpiresByType application/javascript "now plus 1 week" ExpiresByType application/x-javascript "now plus 1 week" # Image files expiration: 1 month after request ExpiresByType image/bmp "now plus 1 month" ExpiresByType image/gif "now plus 1 month" ExpiresByType image/jpeg "now plus 1 month" ExpiresByType image/jp2 "now plus 1 month" ExpiresByType image/pipeg "now plus 1 month" ExpiresByType image/png "now plus 1 month" ExpiresByType image/svg+xml "now plus 1 month" ExpiresByType image/tiff "now plus 1 month" ExpiresByType image/vnd.microsoft.icon "now plus 1 month" ExpiresByType image/x-icon "now plus 1 month" ExpiresByType image/ico "now plus 1 month" ExpiresByType image/icon "now plus 1 month" ExpiresByType text/ico "now plus 1 month" ExpiresByType application/ico "now plus 1 month" ExpiresByType image/vnd.wap.wbmp "now plus 1 month" ExpiresByType application/vnd.wap.wbxml "now plus 1 month" ExpiresByType application/smil "now plus 1 month" # Audio files expiration: 1 month after request ExpiresByType audio/basic "now plus 1 month" ExpiresByType audio/mid "now plus 1 month" ExpiresByType audio/midi "now plus 1 month" ExpiresByType audio/mpeg "now plus 1 month" ExpiresByType audio/x-aiff "now plus 1 month" ExpiresByType audio/x-mpegurl "now plus 1 month" ExpiresByType audio/x-pn-realaudio "now plus 1 month" ExpiresByType audio/x-wav "now plus 1 month" # Movie files expiration: 1 month after request ExpiresByType application/x-shockwave-flash "now plus 1 month" ExpiresByType x-world/x-vrml "now plus 1 month" ExpiresByType video/x-msvideo "now plus 1 month" ExpiresByType video/mpeg "now plus 1 month" ExpiresByType video/mp4 "now plus 1 month" ExpiresByType video/quicktime "now plus 1 month" ExpiresByType video/x-la-asf "now plus 1 month" ExpiresByType video/x-ms-asf "now plus 1 month" Ok, bây giờ bạn CHMOD lại file .htaccess thành 644 nhé. Tối ưu hóa Database Sử dụng WP-Optimize: http://wordpress.org/plugins/wp-optimize/ Sử dụng Cloudflare. Còn nữa ở các kỳ sau!!!