
Speed up your sites with PageSpeed for Nginx - jdorfman
http://googledevelopers.blogspot.com/2013/04/speed-up-your-sites-with-pagespeed-for.html
======
shawabawa3
This didn't work for me, it did something very strange.

I have nginx set up to listen on ssl and proxy everything to my python backend
in plain http (as well as serve static files)

Installing the pagespeed module (without even turning it on), caused nginx to
revert to the default config (it just served the default nginx index.html and
404'd everything else) after the 3rd or 4th request.

Any ideas why this would happen?

~~~
cbr
I've narrowed down the problem to a specific change, and updated the
installation instructions to use a release from last week before that change.
People are reporting that this fixes it for them. I'm going to be putting out
an updated version, probably 1.5.27.2, that also will have this issue fixed.

------
nodesocket
I wish I didn't have to compile from source to install modules, I'd love to
continue to use the official nginx YUM repo.

~~~
cbr
You can do this with Tengine [1], a version of Nginx that supports loadable
modules: [https://github.com/pagespeed/ngx_pagespeed/wiki/Using-
ngx_pa...](https://github.com/pagespeed/ngx_pagespeed/wiki/Using-
ngx_pagespeed-with-Tengine)

[1] <http://tengine.taobao.org/>

------
perlgeek
Am I the only one who is worried that modules like this introduce subtle and
hard-to-find bugs in the served pages? It's a layer you don't usually look at
when debugging web applications.

~~~
skrebbel
Good one. Anyone here got experience with the original Apache mod_pagespeed in
production?

------
cbr
Comments from when someone posted a link to a pre-alpha version:
<https://news.ycombinator.com/item?id=4638712>

------
druiid
Does anyone know if this works when using Nginx as a proxy? That would be
pretty killer if so.

~~~
igrigorik
Yup, in fact, that's exactly how ZippyKid integration is setup:
[https://www.zippykid.com/2013/04/23/partnership-with-
google-...](https://www.zippykid.com/2013/04/23/partnership-with-google-to-
deliver-fast-wordpress-sites/)

It doesn't matter if the files are local or remote, ngx_pagespeed can fetch
from both. Some docs on related functionality:
[https://developers.google.com/speed/docs/mod_pagespeed/domai...](https://developers.google.com/speed/docs/mod_pagespeed/domains)

~~~
druiid
Thanks for the link. I for one will be implementing this then! Probably start
testing tonight actually (I'm excited).

~~~
zippykid
Druiid, do you mind testing our instructions here?
<http://github.com/zippykid/nginx/> ?

~~~
druiid
Sure, I'll take a look at it. Might be able to send you guys some rpm
instructions as well. We are a RH/CentOS shop.

Edit: Looking over your build files. I think I'm going to go ahead and create
(or modify existing) spec files and throw together a github for an nginx RH
tree. If anyone is interested in it when done, shoot me an e-mail through
profile.

~~~
druiid
Can't edit again for some reason.. so here goes for anyone that is interested.
Included modified spec file and built-RPMS:

<https://github.com/justicel/nginx-pagespeed>

Pretty sure github is going to yell at me about the binary files :P

------
ushi
Oooops, <http://ngxpagespeed.com/> (their demonstration site) doesn't respond
at the moment...

~~~
instakill
Still no response 8 hours down the line.

~~~
ushi
It is back now. You can apply single filters and check out the results. It's
nice to play with.

------
jamengual
Instructions on how to install/build deb package for Ubuntu/Debian here
[http://serverfault.com/questions/502764/how-to-build-
nginx-1...](http://serverfault.com/questions/502764/how-to-build-
nginx-1-4-0-and-ngx-pagespeed-in-ubuntu)

------
JeremyMorgan
This is pretty sweet. What optimizations does it do other than offloading
stuff to CDN?

~~~
cbr
All these:
[https://developers.google.com/speed/docs/mod_pagespeed/filte...](https://developers.google.com/speed/docs/mod_pagespeed/filters)
So image optimization, css and js minification, cache extension, css
combining, image spriting, ...

But offloading things to CDN is actually one of the things it _doesn't_ do.
You might be thinking of the PageSpeed Service [1] which is a Google-hosted
version.

[1] <https://developers.google.com/speed/pagespeed/service>

~~~
icelancer
Wow. Thanks for bringing the service to my attention! Cut the load times on my
sites by a ton.

------
jedberg
If I have a static directory of files is there any way to leverage this same
code to just perform the optimizations on my html so I don't have to have the
webserver do it (or so I don't have to run my own webserver)?

~~~
buymorechuck
Probably not without some work. I think you have to get the PageSpeed
Optimization Library and build it from source, as described here:
[https://github.com/pagespeed/ngx_pagespeed/wiki/Building-
PSO...](https://github.com/pagespeed/ngx_pagespeed/wiki/Building-PSOL-From-
Source)

(hi!)

~~~
jedberg
Hmmm. I don't really know C++ well enough to do this myself. Oh well.

Seems like it would be super useful to have a command line version of this so
I could take an html file, pipe it in and get out an optimized file, and then
diff them so I can learn to make my pages better.

I suppose as a hack I could set up nginx with the plugin and then load each
page through curl or something and diff them that way...

~~~
skrebbel
That wouldn't be a 100% match since it assumes HTTP headers and mangles them,
too. For example, it probably uses the MIME type served by the proxied server
to see whether it's css or js or whatever should be minified (I didn't check
the sources for this).

With a pipe, it'd need to use heuristics to figure out what kind of file it
is. That could be added, probably, but it's not entirely trivial.

Additionally, you'd miss out on all the HTTP header mangling, such as cache
expiry settings.

------
joevandyk
I'm hoping heroku can support this. Maybe via a buildpack.

I'd _love_ to get rid of using Sprockets and compiling assets.

ngx_pagespeed should take care of everything Sprockets does, right?

~~~
igrigorik
Yep, it'll concatenate files, minify them, etc., all the things you would
expect. Perhaps the only caveat is: it doesn't do any dependency management,
etc., which sprockets provides (if you actually use that part of it).

------
dantiberian
Wouldn't it be preferable to perform all of these optimizations once before
page load to reduce the work that nginx has to do?

~~~
dangrossman
The work only has to be done once either way; all the file-based optimizations
get cached, they're not run again on every page view.

------
zufallsheld
I tried it on my own little webpage [1]. Results in short: 0.5 seconds to 0.9
seconds shorter load times. Beware, that I only have static content on that
website.

[1] [http://zufallsheld.de/2013/04/26/googles-nginx-plugin-
ngx_pa...](http://zufallsheld.de/2013/04/26/googles-nginx-plugin-
ngx_pagespeed-tested/)

------
growse
This is brilliant, in principle. Getting some odd segfaults to do with
libpthread-2.15.so on Ubuntu 12.10 though, so not sure what's going on there.
I'll dig some more then file a bug...

