Tốc độ load trang web là một điều rất quan trọng, nó cũng là một yếu tố giúp cho web bạn được ghi điểm nhiều hơn trong mắt của Google Search và những công cụ Search khác nữa. Sau đây mình xin giới thiệu đến các bạn một cách hay để giúp cho website của bạn cải thiện tốc độ tải trang. Đầu tiên bạn mở file .htaccess của mình lên và paste đoạn code sau đây: Mã: # Enable Compression <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/vnd.ms-fontobject AddOutputFilterByType DEFLATE application/x-font AddOutputFilterByType DEFLATE application/x-font-opentype AddOutputFilterByType DEFLATE application/x-font-otf AddOutputFilterByType DEFLATE application/x-font-truetype AddOutputFilterByType DEFLATE application/x-font-ttf AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE font/opentype AddOutputFilterByType DEFLATE font/otf AddOutputFilterByType DEFLATE font/ttf AddOutputFilterByType DEFLATE image/svg+xml AddOutputFilterByType DEFLATE image/x-icon AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE text/plain </IfModule> <IfModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file .(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* </IfModule> # Leverage Browser Caching <IfModule mod_expires.c> ExpiresActiveOnExpiresByType image/jpg "access 1 year" ExpiresByType image/jpeg "access 1 year" ExpiresByType image/gif "access 1 year" ExpiresByType image/png "access 1 year" ExpiresByType text/css "access 1 month" ExpiresByType text/html "access 1 month" ExpiresByType application/pdf "access 1 month" ExpiresByType text/x-javascript "access 1 month" ExpiresByType application/x-shockwave-flash "access 1 month" ExpiresByType image/x-icon "access 1 year" ExpiresDefault"access 1 month" </IfModule> <IfModule mod_headers.c> <filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$"> HeadersetCache-Control"max-age=2678400, public" </filesmatch> <filesmatch "\.(html|htm)$"> HeadersetCache-Control"max-age=7200, private, must-revalidate" </filesmatch> <filesmatch "\.(pdf)$"> HeadersetCache-Control"max-age=86400, public" </filesmatch> <filesmatch "\.(js)$"> HeadersetCache-Control"max-age=2678400, private" </filesmatch> </IfModule> Lưu ý: Đối với hình ảnh nếu bạn muốn thêm vào sản phẩm mà bên phía khách hàng thấy liền thì bạn hãy xóa những đoạn code có liên quan đến image nha. Chúc các bạn thành công!
ý nghĩa đoạn code trên là như thế nào vậy bạn, mình xem ko hiểu lắm, áp dụng được cho mọi mã nguồn luôn ah
Áp dụng cho mã nguồn php. Code này dùng để enable gzip và lưu cache cho trình duyệt để tăng tốc tải trang nha bạn.
Cho dù có tối ưu cỡ nào thì cũng không bằng bộ source của website ít file js, nội dung ít hình ảnh và hosting chất lượng. Mình đã từng cố tối ưu bằng các plugin cache cho website, code tay đủ kiểu nhưng mà nó chỉ làm tốn tài nguyên host nên vẫn không cải thiện được gì.
Mình hay tối ưu web bằng cách dùng rất ít file JS và nội dung để kích thước ảnh hợp lí chứ rất ít khi dùng code, vì mình không giỏi về code nên không dùng
xin hỏi ngang 1 tí, mình làm sao mở file để cho bọ googlae tìm các mục bị chặn trong js, cs thế. Chỉnh như thế nào còn đoạn code trên mình copy paste vô là xài được hay sao ạ