Server-side auto-minify?

前端 未结 4 457
不知归路
不知归路 2020-12-31 10:02

Is there any way to automatically minify static content and then serve it from a cache automatically? Similar to have mod_compress/mod_deflate work? Preferably something I c

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-31 10:18

    I decided to do this through PHP (mostly because I didn't feel like writing a lighttpd module).

    My script takes in a query string specifying the type of the files requested (js or css), and then the names of those files. For example, on my site the CSS is added like this:

    This minifies and concatenates style.css and blue.css

    It uses JSMin-PHP and cssmin.

    It also caches the files using XCache if it's available (since minifying is expensive). I actually plan to change the script so it doesn't minify if Xcache isn't available, but I have Xcache and I got bored.

    Anyway, if anyone else wants it, it's here. If you use mine you'll need to change the isAllowed() function to list your files (it may be safe to make it just return true, but it was easy to just list the ones I want to allow).

提交回复
热议问题