Is it possible to set filters by browser?

21 views
Skip to first unread message

Vidyut

unread,
Nov 1, 2015, 8:06:53 AM11/1/15
to ngx-pagesp...@googlegroups.com
If, for example, I want to not combine scripts for spdy/http2 enabled browsers and combine for the rest, how do I do it?

Vidyut

Social Media: Twitter Facebook Google+ Diaspora

Jeff Kaufman

unread,
Nov 1, 2015, 1:14:32 PM11/1/15
to ngx-pagesp...@googlegroups.com
In the upcoming 1.10 release you can use nginx script variables with
the EnableFilters/DisableFilters commands. This would look like this:

http {
...
pagespeed ProcessScriptVariables on;
location / {
set $disablefilters "";

if ($spdy) {
set $disablefilters "list,of,filters,to,disable";
}

pagespeed DisableFilters $disablefilters;
}
}

If you'd like to try this out now, it's a tiny patch:
https://github.com/pagespeed/ngx_pagespeed/commit/afd0f01686e1f06bfff86efd06324d54b2244f9a

See https://developers.google.com/speed/pagespeed/module/domains#LoadFromFileScriptVariables
for more on ProcessScriptVariables.
> --
> You received this message because you are subscribed to the Google Groups
> "ngx-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ngx-pagespeed-di...@googlegroups.com.
> Visit this group at http://groups.google.com/group/ngx-pagespeed-discuss.
> For more options, visit https://groups.google.com/d/optout.

Hans van Eijsden

unread,
Nov 1, 2015, 5:39:31 PM11/1/15
to ngx-pagespeed-discuss
That's great new Jeff. Thanks, I'm looking forward to it.

One thing though: the first thing everybody learns about nginx is "if = evil": https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/ but in the example above, there's "if" in a location block.
Is there a way to do it without "if"?

Hans


Op zondag 1 november 2015 19:14:32 UTC+1 schreef Jeff Kaufman:

Otto van der Schaaf

unread,
Nov 1, 2015, 6:31:39 PM11/1/15
to ngx-pagesp...@googlegroups.com

On Sun, Nov 1, 2015 at 11:39 PM, Hans van Eijsden <hans...@gmail.com> wrote:
One thing though: the first thing everybody learns about nginx is "if = evil": https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/ but in the example above, there's "if" in a location block.
Is there a way to do it without "if"?

Using "if" just to set a variable in a server{} block should work fine (and I think it is also a good place as that also is where protocols are configured). 
So for example, you could configure something like this:
http {
pagespeed ProcessScriptVariables on;
server {
    set $spdy_disable "";

    if ($spdy) {
       set $spdy_disable "combine_css,combine_javascript";
    }
    pagespeed DisableFilters "$spdy_disable";
}
}

In location{} blocks, "if" gets tricky, but it does behave consistently. 
So if a configuration depending on if-in-location works for a single request, it should work for all of them.

Otto

Jeff Kaufman

unread,
Nov 2, 2015, 8:19:52 AM11/2/15
to ngx-pagesp...@googlegroups.com
I realized I don't have draft doc for this feature for the 1.10
release. I've started that doc now, which then reminded me that we
don't support disabling ShardDomain. So I'm adding that too.
> --
> You received this message because you are subscribed to the Google Groups
> "ngx-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ngx-pagespeed-di...@googlegroups.com.

Jeff Kaufman

unread,
Nov 2, 2015, 10:33:51 AM11/2/15
to ngx-pagesp...@googlegroups.com
The configuration I'm planning to recommend for people running http2/spdy is:

http {
pagespeed ProcessScriptVariables on;
server {
set $disable_filters "";
set $domain_shards "shard1,shard2,shard3..."

if ($http2) {
set $disable_filters "combine_css,combine_javascript";
set $domain_shards "";
}
pagespeed DisableFilters "$disable_filters";
pagespeed ShardDomain domain_to_shard "$domain_shards";
}
}

The ShardDomain portion of this needs a psol update, though.

Vidyut

unread,
Nov 5, 2015, 4:25:18 PM11/5/15
to ngx-pagespeed-discuss
Thanks! This is useful. Will play with it a bit when I get time.

I agree IfIsEvil but there should be a way of setting it in another manner to avoid the if. Will figure it out and share back if useful. Map could come in handy.... or something.

Vidyut

Jeff Kaufman

unread,
Nov 7, 2015, 8:04:41 AM11/7/15
to ngx-pagesp...@googlegroups.com
I really don't think we should be trying to avoid the use of "if"
here. Setting a variable in an "if" statement in a server block is
one of the safe ways to use it.
Reply all
Reply to author
Forward
0 new messages