Caching and gzip compression by htaccess

前端 未结 5 609
小鲜肉
小鲜肉 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 18:48

    Enable compression via .htaccess

    For most people reading this, compression is enabled by adding some code to a file called .htaccess on their web host/server. This means going to the file manager (or wherever you go to add or upload files) on your webhost.

    The .htaccess file controls many important things for your site. If you are not familiar with the .htaccess file, please read my working with .htaccess article to get some know how before changing it.

    The code below should be added to your .htaccess file...

    
    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.*
    
    

    Save the .htaccess file and then refresh your webpage.

    Check to see if your compression is working using the Gzip compression tool.

提交回复
热议问题