unlcms / UNL-CMS

Drupal 7 implementation at the University of Nebraska–Lincoln
http://unlcms.unl.edu/
GNU General Public License v2.0
4 stars 13 forks source link

Enable gzip compression and browser caching of resources #890

Open mfairchild365 opened 9 years ago

mfairchild365 commented 9 years ago

see https://developers.google.com/speed/pagespeed/insights/?url=http%3A%2F%2Fwdn.unl.edu%2F&tab=mobile

This is currently an issue for many framework provided assets and should be fixed.

mfairchild365 commented 9 years ago

@tsteiner what would it take to get these issues addressed? It seems fairly easy, but I'm not sure how easy it would be with the current architecture.

tsteiner commented 9 years ago

Silly nginx: when you turn on gzip, it only compresses text/html content. I've told it to compress everything now.

gzip_types *;

Applied on http://unlcms-dr.autosplit.its-sys.unl.edu/. If everything looks ok, I'll do an RFC and get it on production.

mfairchild365 commented 9 years ago

Sweet. Thank you @tsteiner

Do these changes also include browser caching of resources, or just gzip?

tsteiner commented 9 years ago

How long do you want wdn files cached?

mfairchild365 commented 9 years ago

7 days? Do @ericras or @kabel have any thoughts?

saltybeagle commented 9 years ago

Would it be possible to coincide the cache expiration with a regular release timeline or RFC process?

kabel commented 9 years ago

I like @saltybeagle's idea, but I don't know if it is practical in a server configuration. Optimally, 1M (month) would provide long life, but cache busting is probably always going to be an issue until we version our file names better.

kabel commented 9 years ago

The HTML5 Boilerplate comes with a wealth of good server configuration options.

mfairchild365 commented 9 years ago

@kabel are you suggesting not caching until we resolve the issue or only caching for a short time (~1 day)?

kabel commented 9 years ago

No, I would think that one month (our release cycle) is just fine.

tsteiner commented 9 years ago

Is that your final answer?

kabel commented 9 years ago

Yes, good enough.

We've gotta start somewhere and I don't know enough about the varnish/nginx combo to know if we're shooting ourselves in the foot when it comes to cache busting.

tsteiner commented 9 years ago

Config updated on http://unlcms-dr.autosplit.its-sys.unl.edu/ . Let me know if/when to set up an RFC to push to production.

mfairchild365 commented 9 years ago

This appears to be working for me using curl, but not when changing my /etc/hosts file. I tested in two ways:

1: using curl:

curl -IH 'Host: www.unl.edu' -H 'Accept-Encoding: gzip' http://unlcms-dr.autosplit.its-sys.unl.edu/wdn/templates_4.0/css/all.css?dep=4.0.27
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 26 May 2015 14:14:13 GMT
Content-Type: text/css
Last-Modified: Tue, 26 May 2015 07:30:33 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
Cache-Control: public, max-age=2592000
Content-Encoding: gzip
X-Cacheable: Yes
X-Varnish: 426163 360495
Age: 267
Via: 1.1 varnish-v4
Content-Length: 49561
Connection: keep-alive

2: changing my /etc/hosts file. This didn't result in assets being gziped or cached when viewing in a browser. Any idea why?

This is what I added to my hosts file

23.253.150.112 www.unl.edu
23.253.150.112 unlcms.unl.edu
tsteiner commented 9 years ago

I'm not sure. I made the same changes to my hosts file and everything worked as expected:

curl -I --compressed http://unlcms.unl.edu/wdn/templates_4.0/css/all.css?dep=4.0.27
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 26 May 2015 14:30:34 GMT
Content-Type: text/css
Last-Modified: Tue, 26 May 2015 07:30:33 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
Cache-Control: public, max-age=2592000
Content-Encoding: gzip
X-Cacheable: Yes
X-Varnish: 557109
Age: 0
Via: 1.1 varnish-v4
Connection: keep-alive
kabel commented 9 years ago

Works for me too, albeit, not with the IPs you had in your host file as those appear to be the production IPs.

tsteiner commented 9 years ago
host 23.253.150.112
112.150.253.23.in-addr.arpa domain name pointer unlcms-dr-web-node-alpha.iad.rackspace.its-sys.unl.edu.

Looks like a DR server to me

kabel commented 9 years ago

Ah, good point, read right over those extra letters. :facepunch:

mfairchild365 commented 9 years ago

I blame my browser, it appears to be working now.

However, I did notice that curl -I --compressed http://www.unl.edu/splash/ isn't being gzipped, but curl -I --compressed http://unlcms.unl.edu/ is.

tsteiner commented 9 years ago

Varnish is now setup to compress any uncompressed content of MIME type text/* (on the DR servers)