Tối ưu performance

Backend

MySQL

Cài đặt và chạy MySQL Tuner để lấy các recommendation.

Query

Cài đặt Query Monitor để phát hiện các query trùng lặp, các query chậm.

Tối ưu các query theo hướng dẫn của 10up. Chú ý 3 điểm sau:

  • 'no_found_rows' => true : Nếu không cần found_posts
  • 'update_post_term_cache' => false : Nếu không cần get term, get category cho các bài viết
  • 'update_post_meta_cache' => false : Nếu query cần get post meta (bao gồm cả thumbnail)

Cache post meta và term meta: update_postmeta_cache và update_termmeta_cache trước để khi get term meta và get post meta không cần phải chạy lại các queries SQL.

Ví dụ: cache post thumbnail

 

$post_thumbnails = [];
foreach ( $query->posts as $recent_post ) {
    $post_thumbnails[] = get_post_meta( $recent_post->ID, '_thumbnail_id', true );
}
update_postmeta_cache( $post_thubmnails );

PHP Workers and WordPress: The Definitive Guide

Khác

Deactivate các plugins mà:

  • Update vào database mỗi khi load (VD: post views)
  • Tải nặng (VD: Redirection)
  • Không cần thiết

Frontend

Chỉnh lại rule .htaccess để cache các file tĩnh trên server.

Tắt Email Address Obfuscation trong CloudFlare.

Gom và inline CSS: dùng plugin Autoptimize

Dequeue hết các script và style không dùng (genericon, Facebook Like, … của Jetpack) hoặc lazyload nó dùng loadCSS.

Xử lý hình ảnh: Dùng CDN của WordPress.com: https://developer.wordpress.com/docs/photon/api/. Xử lý cho tất cả các chỗ insert được URL bằng tay.

Resize, tối ưu hình ảnh sau khi upload: tham khảo plugin Imsanity.

Preload các ảnh hero.

Lazyload hình ảnh: dùng lazy load của Autoptimize hoặc thư viện

Icon fonts: dùng loadCSS.

Tối ưu Google Fonts: tham khảo Meta Box và CSSWizardry.

Tối ưu video/iframe và các widget bên thứ 3: tham khảo Meta Box và bài này.

Cheatsheet để tối ưu các chỉ số Web Vitals.

BÀI VIẾT LIÊN QUAN

Liên hệ ngay