CSS/JS On-the-fly Minification? (Performance)
I'm working off the List of Google Pagespeed's guidelines for speeding up pageload times. One of them is minifying CSS and JS f开发者_C百科iles.
Since these files change quite often I was thinking of using a PHP script that minifies this script on-the-fly upon request (from the browser).
Or do you think this is a bad idea? After all, it would result in static resources having to be passed through a php script before delivering them.
On-the-fly minification scripts are fairly advanced and use caching to ensure that scripts aren't minified on every single call.
You can use something like http://code.google.com/p/minify/
If you are using a shared hosting maybe interesting this option:
https://www.minifier.org/
and you could minify css or js on the fly.
According to my tests on the fly minification with that library:
- execution time without on the fly minification: 0.0006 seconds
- execution time with on the fly minification: 0.13 seconds and Save 20Kb
As you can see without minification (a simple echo) my sample script has been executed 200 times faster than using minification.
You must assess the advantages and disadvantages according to your application but you could generate cached files and only use minification in the first call.
精彩评论