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

前端 未结 5 1971
轻奢々
轻奢々 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:06

    You can try your luck with mod_rewrite.

    Create a script that takes a local static file name as input, through e.g. $_SERVER['QUERY_STRING'] and outputs it in compressed form. Many providers don't allow configuring mod_rewrite with .htaccess files or have it completely disabled though.

    If you haven't used rewrite before, I recommend a good beginner's guide, like probably this one. This way you can make the apache redirect all requests for a static file to a php script. style.css will be redirected to compress.php?style.css for instance.

    As always be extremely cautious on the input you accept or you have an XSS exploit on your hands!

提交回复
热议问题