April 2, 2025

Tối ưu Lighthouse Score: Các bước giúp trang web của bạn đạt điểm cao
Hướng dẫn tối ưu hiệu suất, accessibility, SEO và best practices để cải thiện Lighthouse Score.
Lighthouse Score là gì?
Lighthouse là một công cụ mã nguồn mở của Google giúp đánh giá chất lượng trang web dựa trên các tiêu chí:
- Performance (Hiệu suất)
- Accessibility (Khả năng truy cập)
- Best Practices (Thực hành tốt nhất)
- SEO (Tối ưu công cụ tìm kiếm)
Mỗi tiêu chí có thang điểm từ 0 đến 100, điểm càng cao chứng tỏ trang web càng tối ưu.
1. Tối ưu Performance (Hiệu suất)
a) Giảm kích thước và số lượng request
- Nén hình ảnh bằng WebP hoặc AVIF thay vì JPEG/PNG.
- Lazy Load hình ảnh và video để chỉ tải khi cần thiết.
- Sử dụng CDN để tải tài nguyên nhanh hơn từ máy chủ gần nhất.
b) Cải thiện tốc độ tải trang
- Nén tài nguyên bằng Gzip hoặc Brotli.
- Tối ưu CSS và JavaScript bằng cách loại bỏ code không sử dụng (tree shaking, minify).
- Sử dụng cache hiệu quả bằng cách đặt
Cache-Control
hợp lý.
c) Giảm thời gian render
- Prefetch, Preload, và Preconnect để tối ưu hóa quá trình tải dữ liệu.
- Sử dụng Server-Side Rendering (SSR) hoặc Static Site Generation (SSG) nếu dùng Next.js hoặc Nuxt.js.
2. Cải thiện Accessibility (Khả năng truy cập)
- Thêm alt cho hình ảnh để hỗ trợ trình đọc màn hình.
- Đảm bảo contrast màu sắc giữa chữ và nền để dễ đọc.
- Sử dụng semantic HTML (
<header>
,<main>
,<section>
,<button>
, ...). - Cung cấp keyboard navigation để hỗ trợ người dùng không dùng chuột.
3. Tuân thủ Best Practices
- Sử dụng HTTPS để bảo mật dữ liệu.
- Tránh sử dụng thư viện lỗi thời và kiểm tra
console.warn
trong DevTools. - Tránh tải JavaScript chặn render bằng cách dùng
defer
hoặcasync
. - Kiểm tra lỗi console và tối ưu security headers (
Content-Security-Policy
).
4. Cải thiện SEO
- Cung cấp metadata đầy đủ (
title
,meta description
,og:image
,og:title
). - Tạo sitemap.xml và robots.txt để giúp công cụ tìm kiếm crawl tốt hơn.
- Sử dụng structured data (Schema Markup) để hiển thị rich snippets.
- Tối ưu tốc độ mobile vì Google ưu tiên mobile-first indexing.
5. Cách kiểm tra Lighthouse Score và theo dõi cải tiến
- Dùng Chrome DevTools (
F12 > Lighthouse
) - Sử dụng PageSpeed Insights (pagespeed.web.dev)
- Kiểm tra bằng Lighthouse CI trong pipeline CI/CD
Tổng kết
✅ Giảm request và tối ưu tài nguyên để tăng Performance.
✅ Tối ưu Accessibility để trang web dễ tiếp cận hơn.
✅ Tuân thủ Best Practices để tránh lỗi bảo mật và coding lỗi thời.
✅ Cải thiện SEO để tăng thứ hạng tìm kiếm.
Lighthouse Score không chỉ giúp tăng tốc độ trang mà còn cải thiện trải nghiệm người dùng và SEO. Hãy bắt đầu tối ưu ngay hôm nay! 🚀
Optimizing Lighthouse Score: Steps to Achieve a High Score
A guide to optimizing performance, accessibility, SEO, and best practices to improve Lighthouse Score.
What is Lighthouse Score?
Lighthouse is an open-source tool by Google that evaluates the quality of a webpage based on the following criteria:
- Performance
- Accessibility
- Best Practices
- SEO
Each criterion is scored from 0 to 100, with higher scores indicating better optimization of the webpage.
1. Optimizing Performance
a) Reduce size and number of requests
- Compress images using WebP or AVIF instead of JPEG/PNG.
- Lazy load images and videos so they load only when necessary.
- Use a CDN to load resources faster from the nearest server.
b) Improve page load speed
- Compress resources using Gzip or Brotli.
- Optimize CSS and JavaScript by removing unused code (tree shaking, minification).
- Use effective caching by setting
Cache-Control
appropriately.
c) Reduce render time
- Prefetch, Preload, and Preconnect to optimize data loading.
- Use Server-Side Rendering (SSR) or Static Site Generation (SSG) if using Next.js or Nuxt.js.
2. Improve Accessibility
- Add alt text for images to support screen readers.
- Ensure color contrast between text and background for readability.
- Use semantic HTML (
<header>
,<main>
,<section>
,<button>
, ...). - Provide keyboard navigation to support users who don't use a mouse.
3. Follow Best Practices
- Use HTTPS for data security.
- Avoid outdated libraries and check for
console.warn
in DevTools. - Avoid blocking JavaScript rendering by using
defer
orasync
. - Check for console errors and optimize security headers (
Content-Security-Policy
).
4. Improve SEO
- Provide complete metadata (
title
,meta description
,og:image
,og:title
). - Create a sitemap.xml and robots.txt to help search engines crawl the site better.
- Use structured data (Schema Markup) for rich snippets.
- Optimize mobile speed since Google prioritizes mobile-first indexing.
5. How to Check Lighthouse Score and Track Improvements
- Use Chrome DevTools (
F12 > Lighthouse
). - Use PageSpeed Insights (pagespeed.web.dev).
- Check with Lighthouse CI in your CI/CD pipeline.
Summary
✅ Reduce requests and optimize resources to increase Performance.
✅ Optimize Accessibility to make your website more accessible.
✅ Follow Best Practices to avoid security issues and outdated coding practices.
✅ Improve SEO to enhance search engine ranking.
Lighthouse Score not only helps speed up the page but also improves user experience and SEO. Start optimizing today! 🚀