Best way to compress HTML, CSS & JS with mod_deflate and mod_gzip disabled

前端 未结 5 1975
轻奢々
轻奢々 2021-02-20 17:48

I have a few sites on a shared host that is running Apache 2. I would like to compress the HTML, CSS and Javascript that is delivered to the browser. The host has disabled mod_d

5条回答
  •  被撕碎了的回忆
    2021-02-20 18:01

    What I do:

    • I place scripts in a js and stylesheets in a css dir, respectively.
    • In the Apache configuration, I add directives like so:

      
          AddHandler application/x-httpd-php .js
          php_value auto_prepend_file gzip-js.php
          php_flag zlib.output_compression On
      
      
          AddHandler application/x-httpd-php .css
          php_value auto_prepend_file gzip-css.php
          php_flag zlib.output_compression On
      
      
    • gzip-js.php in the js directory looks like this:

      
      
    • …and gzip-cs.php in the css directory looks like this:

      
      

    This may not be the most elegant solution, but it most certainly is a simple one that requires few changes and works well.

提交回复
热议问题