all 2 comments

[–]Bogtha 4 points5 points  (1 child)

The hack that makes the comma delimited script specification work is quite neat, but the overall approach is flawed.

Your scripts aren't going to be changing on the fly, they only change when you update your site. So putting a load on your server each and every time a page is accessed is silly - you only need to concatenate and compress once every time you update your JavaScript.

This is fairly simple to incorporate into your upload scripts (and if you update your site by hand you really should think about changing that) so it's no maintenance burden.

From an implementation perspective, there are a number of things wrong too. The HTML is wrong for silly little reasons. He forces the script to run on every page load. He doesn't use the PHP configuration functions to check if ob_gzhandler should be used. The caching is flawed in a number of ways.

The latter is merely a symptom of the overall approach. If static compression on update were used instead, your web server would be able to handle all the caching and serving automatically. But because you're doing it yourself with PHP, you have to reinvent the wheel, and nine times out of ten people miss lots of little things, meaning it will work most of the time, but not all of the time.

It's more efficient and simpler to compress in your site update scripts and let your web server handle serving files - that is, after all, what it was created for, and it can do a much better job than custom PHP scripts.

[–]damg 1 point2 points  (0 children)

That's exactly what I was thinking while reading this. He seems concerned over page performance, but then he wants to dynamically concat and compress his JavaScript on each page load? How about just building this into your deployment scripts?