Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precendence over gzip #11

Closed
toastal opened this issue Jan 12, 2016 · 18 comments

Comments

@toastal
Copy link

@toastal toastal commented Jan 12, 2016

My Firefox browser is set to Accept-Encoding: br, gzip, deflate. I have both gzip and brotli turned on on the server, but gzip seems to take precedence over brotli when I view Content-Encoding for the response. If I turn off gzip on the server or take gzip off the Accept-Encoding from the browser's request, I'll get "br" as the Content-Encoding. Is there a way to change this?

Latest pull on brotli & ngx_brotli, nginx 1.9.7.rc1 (openresty)
Firefox v45.0a

@PiotrSikora

This comment has been minimized.

Copy link
Member

@PiotrSikora PiotrSikora commented Jan 14, 2016

I cannot replicate this (neither with vanilla nginx-1.9.7 nor with ngx_openresty-1.9.7.1).

What website are you testing this with? Do you have any proxies or CDN in between?

@toastal

This comment has been minimized.

Copy link
Author

@toastal toastal commented Jan 14, 2016

I was testing my personal page placeholder @ https://toast.al/ . There's no proxies/CDN between my content and the user. According to my config, the HTML and CSS should be using brotli. I also have gzip and brotli static both enabled.. with %f.gz & %f.br files in the directory.

@toastal

This comment has been minimized.

Copy link
Author

@toastal toastal commented Jan 14, 2016

Actually, here's the relevant Nginx config lines:

    ...

    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_static on;

    brotli on;
    brotli_types text/html text/css text/javascript application/javascript application/json image/svg+xml;
    brotli_static on;

    ...
@toastal

This comment has been minimized.

Copy link
Author

@toastal toastal commented Jan 14, 2016

If it helps, here's my source for the site as well as my build steps for the server in the README: https://bitbucket.org/toastal/toast.al-social-page/src

@PiotrSikora

This comment has been minimized.

Copy link
Member

@PiotrSikora PiotrSikora commented Jan 15, 2016

Are you sure that your web application doesn't send compressed (read: gzipped) responses?

ngx_brotli doesn't re-compress already compressed responses, so if it's gzipped before reaching nginx, it will be passed to the client as such.

@toastal

This comment has been minimized.

Copy link
Author

@toastal toastal commented Jan 15, 2016

I'm not 100% sure what you're asking about compressed responses and apps...

The two files are static, an index.html file and a main.css file. There's no app being proxied to or anything like that. Both files however do have a precompressed version for gzip_static and brotli_static.

The dist directory being served from looks like this currently:

Σ /v/w/t/dist (master=) tree .
.
├── css
│   ├── main.css
│   ├── main.css.br
│   └── main.css.gz
├── fonts
│   └── fantasque-sans-mono
│       ├── FantasqueSansMono-BoldItalic.woff
│       ├── FantasqueSansMono-BoldItalic.woff2
│       ├── FantasqueSansMono-Bold.woff
│       ├── FantasqueSansMono-Bold.woff2
│       ├── FantasqueSansMono-Italic.woff
│       ├── FantasqueSansMono-Italic.woff2
│       ├── FantasqueSansMono-Regular.woff
│       └── FantasqueSansMono-Regular.woff2
├── index.html
├── index.html.br
├── index.html.gz
└── robots.txt

3 directories, 15 files
@PiotrSikora

This comment has been minimized.

Copy link
Member

@PiotrSikora PiotrSikora commented Jan 15, 2016

Well, I don't know your nginx.conf (can you share it, please? Ideally, just minimal version that you're able to replicate this with), so I'm trying to guess what might be the source of this weird behavior.

Brotli takes precedence over gzip in all my tests...

@toastal

This comment has been minimized.

Copy link
Author

@toastal toastal commented Jan 15, 2016

worker_processes  4;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_static on;

    brotli on;
    brotli_types text/html text/css text/javascript application/javascript application/json image/svg+xml;
    brotli_static on;

    server_tokens off;

    server {
        listen       80;
        server_name  toast.al;
        rewrite ^ https://$server_name$request_uri? permanent;
    }


    # HTTPS server

    server {
        listen       443 default_server ssl http2;
        server_name  toast.al;

        add_header X-Frame-Options SAMEORIGIN;
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Content-Type-Options nosniff;
        add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";

        ... ssl stuff ...

        location / {
            root  /var/www/toast.al-social-page/dist;
            index index.html index.htm;
        }
    }

    server {
       listen 80;
       listen 443 ssl http2;
       server_name www.toast.al;
       return 301  $scheme://toast.al$request_uri;
    }

}
@PiotrSikora

This comment has been minimized.

Copy link
Member

@PiotrSikora PiotrSikora commented Jan 22, 2016

I still cannot replicate this issue, even when using your config...

Could you give me the git commit of ngx_brotli that you've checked out?

Also, could you provide a debug log of the gzipped request?

@toastal

This comment has been minimized.

Copy link
Author

@toastal toastal commented Jan 22, 2016

Derp. So it wasn't this module. The output of the bro command to a *.br file doesn't have read permissions. Sorry about that--I saw the files in the directory and assumed the command would transfer permissions.

@toastal toastal closed this Jan 22, 2016
@angristan

This comment has been minimized.

Copy link

@angristan angristan commented Jan 31, 2016

Ho to set Accept-Encoding: br ?

@toastal

This comment has been minimized.

Copy link
Author

@toastal toastal commented Jan 31, 2016

If you're asking "how" to set it from the browser, only the Firefox 44+ and latest dev Chromium (behind a flag) support brotli. You'll need one of the supported browsers and they will add the accepted encoding by default.

@angristan

This comment has been minimized.

Copy link

@angristan angristan commented Jan 31, 2016

Okay I updated Firefox to version 44 and I have this : Accept-Encoding :"gzip, deflate, br"
Is this the good order ?

@toastal

This comment has been minimized.

Copy link
Author

@toastal toastal commented Jan 31, 2016

Order shouldn't matter. But if you're interested, it can be modified at about:config rule network.http.accept-encoding.secure.

@angristan

This comment has been minimized.

Copy link

@angristan angristan commented Jan 31, 2016

Thanks. I do I know if my web server is correctly configured with Brotli ?

@toastal

This comment has been minimized.

Copy link
Author

@toastal toastal commented Jan 31, 2016

How do you know? You can inspect a resource from Firefox's Network tab that should have the encoding. In the response headers of that resource you should see Content-Encoding: "br".

@angristan

This comment has been minimized.

Copy link

@angristan angristan commented Feb 1, 2016

I don't have it :/
screenshot_01-02-2016_01qdj4hy

@toastal

This comment has been minimized.

Copy link
Author

@toastal toastal commented Feb 1, 2016

headers-brotli Mine's working fine.

eustas added a commit that referenced this issue Sep 3, 2019
Perhaps, it will help with #11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.