Tăng tốc website với file .htaccess

Thảo luận trong 'Thủ thuật - Chiến lược SEO' bắt đầu bởi mrpham2589, 21/6/16.

Đã xem: 300

  1. mrpham2589 Thành Viên Tích Cực

    Với những ai muốn tối ưu tăng tốc độ website thì chắc không thể không nhắc tới công cụ Yslow. Cơ chế tính điểm của Yslow là càng giảm thiểu số lần request đến server thì bạn càng có số điểm cao, và khi đó tốc độ website của bạn cũng được cải thiện một cách đáng kể.
    Sử dụng Module Mod_Deflare để tối ưu Yslow

    Với những bạn xài host nền tảng Apache 2.0 thì có 1 module khác được tích hợp sẵn trong Apache là mod_deflare.
    Chèn đoạn code sau vào file .htaccess của bạn

    # BEGIN Compress text files
    <IfModule mod_deflate.c>
    <FilesMatch "\.(css|js|x?html?|php)$">
    SetOutputFilter DEFLATE
    </FilesMatch>
    </IfModule>
    # END Compress text files

    # BEGIN Expire headers
    <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 1 seconds"
    ExpiresByType image/x-icon "access plus 2592000 seconds"
    ExpiresByType image/jpeg "access plus 2592000 seconds"
    ExpiresByType image/png "access plus 2592000 seconds"
    ExpiresByType image/gif "access plus 2592000 seconds"
    ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
    ExpiresByType text/css "access plus 604800 seconds"
    ExpiresByType text/javascript "access plus 216000 seconds"
    ExpiresByType application/javascript "access plus 216000 seconds"
    ExpiresByType application/x-javascript "access plus 216000 seconds"
    ExpiresByType text/html "access plus 600 seconds"
    ExpiresByType application/xhtml+xml "access plus 600 seconds"
    </IfModule>
    # END Expire headers

    # BEGIN Cache-Control Headers
    <IfModule mod_headers.c>
    <FilesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
    </FilesMatch>
    <FilesMatch "\.(css)$">
    Header set Cache-Control "max-age=604800, public"
    </FilesMatch>
    <FilesMatch "\.(js)$">
    Header set Cache-Control "max-age=216000, private"
    </FilesMatch>
    <FilesMatch "\.(x?html?|php)$">
    Header set Cache-Control "max-age=600, private, must-revalidate"
    </FilesMatch>
    </IfModule>
    # END Cache-Control Headers

    # BEGIN Turn ETags Off
    <IfModule mod_headers.c>
    Header unset ETag
    </IfModule>
    FileETag None
    # END Turn ETags Off

    # BEGIN Remove Last-Modified Header
    <IfModule mod_headers.c>
    Header unset Last-Modified
    </IfModule>
    # END Remove Last-Modified Header
    Các bạn dán các dòng lệnh trên vào file .htaccess và bạn sẽ thấy chỉ số yslow của bạn tăng đáng kể. Tuy nhiên để có thể lên được các chỉ số tối đa, bạn cần phải mua dịch vụ CDN. dịch vụ đó bạn lên Google search nhé !

    Hãy thử và comment lại kết quả vào bên dưới để anh em cùng biết và khắc phục nhé !
     
    Hình nấm lim xanh thật
    Đang tải...
    nam lim xanh

    Bình Luận Bằng Facebook