11:46 AM
0
Webserver phải cài gzip. Với apache, module tên là "deflate", module này phải được install và enable ở service apache.
Thêm các dòng sau vào file .htaccess ở thư mục gốc webserver:
## module gzip

    SetOutputFilter DEFLATE
    ## type file compress
    AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript application/x-httpd-php
    #### old browser
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
    #### not compress image
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
    Header append Vary User-Agent env=!dont-vary


# Expires Headers - 2678400s = 31 days

    ExpiresActive On
    ExpiresDefault "access plus 1 seconds"
    ExpiresByType text/html "access plus 7200 seconds"
    ExpiresByType image/gif "access plus 2678400 seconds"
    ExpiresByType image/jpeg "access plus 2678400 seconds"
    ExpiresByType image/png "access plus 2678400 seconds"
    ExpiresByType text/css "access plus 518400 seconds"
    ExpiresByType text/javascript "access plus 2678400 seconds"
    ExpiresByType application/x-javascript "access plus 2678400 seconds"


# Cache Headers

    # Cache specified files for 31 days
   
        Header set Cache-Control "max-age=2678400, public"
   
    # Cache HTML files for a couple hours
   
        Header set Cache-Control "max-age=7200, private, must-revalidate"
   
    # Cache PDFs for a day
   
        Header set Cache-Control "max-age=86400, public"
   
    # Cache Javascripts for 31 days
   
        Header set Cache-Control "max-age=2678400, private"
   

0 comments:

Post a Comment