Bật nén Gzip cho wordpress thông qua .htaccess – WordPress Developer

Cập nhật lần cuối 17/03/2017 by Mr Toản trong WordPress vào 21/01/2014 có

Tại sao chúng ta cần bật nén Gzip cho website?

Nén Gzip cho website sẽ giúp cho web của bạn load với tốc độ nhanh hơn rất nhiều lần. Và giảm được khoảng 70% dung lượng của web khi mở bằng trình duyệt.

Lợi ích

  1. Nhiều khả năng thích nghi với kết quả tìm kiếm
  2. Giảm bớt yêu cầu về máy chủ của bạn
  3. 1000KB sẽ được chuyển thành 100KB

Enable-Gzip-CompressionEnable-Gzip-Compression
có nhiều cách nén có thể dùng plugin hoặc .htaccess. Dưới đây là cách dùng với file .htaccess

Bật nén Gzip trong wordpress thông quá .htaccess

Thêm đoạn code sau vào file .htaccess trong thư mục gốc ngang hàng với wp-admin nhé

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month" 
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##
# 1 Month for all your static assets
<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|woff)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>

# 1 DAYS for rss feeds and robots
<filesMatch ".(xml|txt)$">
Header set Cache-Control "max-age=86400, public, must-revalidate"
</filesMatch>

# 4 HOURS for your real articles files
<filesMatch ".(html|htm)$">
Header set Cache-Control "max-age=14400, must-revalidate"
</filesMatch>

<IfModule mod_deflate.c>
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddType x-font/otf .otf
AddType x-font/ttf .ttf
AddType x-font/eot .eot
AddType x-font/woff .woff
AddType image/x-icon .ico
AddType image/png .png
</IfModule>

Công cụ giúp các bạn kiểm tra tốc độ web cũng như giúp bạn tối ưu Google

Chúc các bạn thành công ^^

Xem thêm tại đây http://softstribe.com/wordpress/enable-gzip-compression-in-wordpress

4.3/5 – (7 votes)

Bài viết có ích cho bạn? Hãy chia sẻ ngay: