Caching and gzip compression by htaccess

前端 未结 5 608
小鲜肉
小鲜肉 2020-12-12 18:05

Can someone provide me with an optimized .htaccess configuration that handles compression, browser caching, proxy caching, etc. for a typical website?

Aside from my

5条回答
  •  独厮守ぢ
    2020-12-12 19:05

    Try this:

    
        #The following line is enough for .js and .css
        AddOutputFilter DEFLATE js css
        AddOutputFilterByType DEFLATE text/plain text/xml application/xhtml+xml text/css   application/xml application/rss+xml application/atom_xml application/x-javascript application/x-httpd-php application/x-httpd-fastphp text/html
    
        #The following lines are to avoid bugs with some browsers
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
        BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    
    
    # BEGIN EXPIRES
    
        ExpiresActive On
        ExpiresDefault "access plus 10 days"
        ExpiresByType text/css "access plus 1 week"
        ExpiresByType text/plain "access plus 1 month"
        ExpiresByType image/gif "access plus 1 month"
        ExpiresByType image/png "access plus 1 month"
        ExpiresByType image/jpeg "access plus 1 month"
        ExpiresByType application/x-javascript "access plus 1 month"
        ExpiresByType application/javascript "access plus 1 week"
        ExpiresByType application/x-icon "access plus 1 year"
    
    # END EXPIRES
    
    
        
            Header append Vary Accept-Encoding
        
        
            Header set Cache-Control "public"
        
        
            Header set Cache-Control "public"
        
        
            Header set Cache-Control "private"
        
        
            Header set Cache-Control "private, must-revalidate"
        
    
    

提交回复
热议问题