2

Can ngx_pagespeed, mod_pagespeed and other such modules that optimize javascript/css at the server level act as a replacement for command-line tools like uglifyjs or yui-compressor?

Cœur
  • 37,241
  • 25
  • 195
  • 267

4 Answers4

1

Yes. PageSpeed includes the rewrite_javascript filter which does very similar minification to uglifyjs and yui-compressor. It's one of the filters that is enabled by default when you install the module.

Jeff Kaufman
  • 575
  • 3
  • 13
1

Yes, they can. But you lack control of what will be aggregated and *_pagespeed will aggregate and minify on a per page policy. This means that if you have two pages which all share one base file (e.g. base.css) and each page has it's own static file as well (e.g. page1.css and page2.css) *_pagespeed is going to aggregate and minify two different cached files for you. This means that your users will have a prime cache when they go from page 1 to page 2 because the static files have changed.

If you want or even need full control over aggregation and minification, the answer is no, it can't be used as a replacement. The pagespeed modules from Google are mainly meant for hosting companies where the users lack the ability to optimize their own resources. Those companies can greatly reduce network traffic and improve the user experience with their hosted products. For a professionally developed web project you'll definitely want to implement this yourself and have full control.

Fleshgrinder
  • 15,703
  • 4
  • 47
  • 56
  • at work I think we only minify/uglify, combining css and js ain't fun. however, the pagespeed docs say you can limit resource combination by sticking them into `location` blocks in nginx. I'm not even sure of the last time I saw a site combine all of the JS and CSS it has into just one or two files...the pagespeed docs suggest combining **external** CSS and JS, not site-specific resources –  Jun 23 '13 at 19:17
  • 1
    Not combining as much as humanly possible into as less files as humanly possible means many HTTP requests and this is going to slow down your site extremely. Even if you are using far future expires headers because the browser will still ask for a newer version of any of the files if the user e.g. reloads a page he is currently on, etc. etc. Good software like Drupal is automatically doing things like this for your and afterwards you'll end up with only one or two files. That should be the goal of your apps as well. Of course you should automate this process. – Fleshgrinder Jun 23 '13 at 19:28
0

If combining /minifying is your only goal, you're better off running mod_pagespeed at the development server, saving the results and deploying that. Mod_pagespeed does a whole lot more and it's the sum of its parts that is it's added value, not it's components individually.

  • won't work in our case, we're using the Django development server, at my previous job I was using Rails which also has its own development server :S –  Jun 24 '13 at 11:48
0

We are currently using google pagespeed for nginx and it does minifies js automatically. But not really good - compared to UglifyJs 3 there is 20% oversize.

File minified with pagespeed is 248Kb. If we run it through Uglify 3 it gets 196 Kb...

Denis Matafonov
  • 2,684
  • 23
  • 30