Dưới đây là một số hướng dẫn và mã bạn có thể sử dụng để tối ưu hóa tốc độ trang web mà bạn có thể kiểm tra tại đây https://developers.google.com/speed/pagespeed/insights/?hl=en
- Cài đặt plugin Autoptimize và đặt các tùy chọn tiếp theo:
- Cài đặt plugin WP Super Cache
- Cài đặt plugin Nén hình ảnh JPEG & PNG
- Đặt tùy chọn của bạn ở đây '/wp-admin/options-general.php?page=tinify'
- Cài đặt plugin Vô hiệu hóa Nhúng
- Cài đặt plugin Tắt biểu tượng cảm xúc (thân thiện với GDPR)
- Thêm mã tiếp theo vào tệp chủ đề wordpress hiện tại của bạn functions.php:123456789101112131415161718192021222324add_filter('autoptimize_html_after_minify', function($content) {$site_url = 'https://YOUR_SITE_LINK_HERE';//do not set slash on the end$content = str_replace("", ' ', $content);$content = str_replace('', ' ', $content);$content = str_replace(" ", ' ', $content);$content = str_replace(' ', ' ', $content);$content = str_replace("rel='stylesheet preload' as='style'", "rel='stylesheet preload'", $content);$content = str_replace('rel="stylesheet preload" as="style"', 'rel="stylesheet preload"', $content);$content = str_replace('@font-face {font-display: swap; ', '@font-face {font-display: swap; font-display: swap;', $content);$content = str_replace('@font-face {font-display: swap; ', '@font-face {font-display: swap; font-display: swap;', $content);$content = str_replace("<img", "<img loading='lazy'", $content);$content = str_replace($site_url . '/wp-includes/js', '/wp-includes/js', $content);$content = str_replace($site_url . '/wp-content/cache/autoptimize', '/wp-content/cache/autoptimize', $content);$content = str_replace($site_url . '/wp-content/themes/', '/wp-content/themes/', $content);$content = str_replace($site_url . '/wp-content/uploads/', '/wp-content/uploads/', $content);$content = str_replace($site_url . '/wp-content/plugins/', '/wp-content/plugins/', $content);return $content;}, 9999, 1);
- Ngoài ra còn có thể tối ưu hóa jquery.js được loại trừ trong Autoptimize, nhưng cách này không phải lúc nào cũng hiệu quả, vì vậy hãy kiểm tra chức năng trang web của bạn sau:
- trong trang web của bạn tập tin chủ đề wp hiện tại functions.php thêm mã tiếp theo:1234//exlude jquery to print it in the header by file_get_contentsadd_action('wp_enqueue_scripts', function () {wp_deregister_script('jquery');});
- trong trang web của bạn tập tin chủ đề wp hiện tại functions.php thêm mã tiếp theo trước :123<script><?php echo file_get_contents(ABSPATH . WPINC . '/js/jquery/jquery.js'); ?></script>
- trong trang web của bạn tập tin chủ đề wp hiện tại functions.php thêm mã tiếp theo:
- hãy quan tâm với jquery.js tối ưu hóa